How can I implement a character echo on the telnet window?

I want to display a character on the telnet window every time the character is input.(character echo).

The following telnet_recv() function display a string(full character) when the enter key is pressed after characters input.

static err_t telnet_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
{
  struct pbuf *q;
  struct name *name = (struct name *)arg;
  int done;
  char *c;
  int i;

  /* We perform here any necessary processing on the pbuf */
  if (p != NULL) 
  {        
  /* We call this function to tell the LwIp that we have processed the data */
  /* This lets the stack advertise a larger window, so more data can be received*/
  tcp_recved(pcb, p->tot_len);

    /* Check the name if NULL, no data passed, return withh illegal argument error */
  if(!name) 
    {
      pbuf_free(p);
      return ERR_ARG;
    }

    done = 0;
    for(q=p; q != NULL; q = q->next) 
    {
      c = q->payload;
      for(i=0; i<q->len && !done; i++) 
      {
        done = ((c(i) == 'r') || (c(i) == 'n'));
        if(name->length < MAX_NAME_SIZE) 
        {
          name->bytes(name->length++) = c(i);
        }
      }
    }
    if(done) 
    {
      if(name->bytes(name->length-2) != 'r' || name->bytes(name->length-1) != 'n') 
      {
        if((name->bytes(name->length-1) == 'r' || name->bytes(name->length-1) == 'n') && (name->length+1 <= MAX_NAME_SIZE)) 
        {
        name->length += 1;
        } 
        else if(name->length+2 <= MAX_NAME_SIZE) 
        {
          name->length += 2;
        } 
        else 
        {
          name->length = MAX_NAME_SIZE;
        }

        name->bytes(name->length-2) = 'r';
        name->bytes(name->length-1) = 'n';
      }

      tcp_write(pcb, name->bytes, name->length, TCP_WRITE_FLAG_COPY);

      name->length = 0;
    }

  /* End of processing, we free the pbuf */
    pbuf_free(p);
  }  
  else if (err == ERR_OK) 
  {
    /* When the pbuf is NULL and the err is ERR_OK, the remote end is closing the connection. */
    /* We free the allocated memory and we close the connection */
    mem_free(name);
    return tcp_close(pcb);
  }

  return ERR_OK;
}

How can I implement this character transfer?

Thanks.

angular – Dynamically setting styleUrls for component based on the current window location

I’m trying to set an angular component styleUrls value based on a condition window.location.href.includes('en')

home-page.component.ts:

let condition = window.location.href.includes('en');

@Component({
    selector: 'app-home-page',
    templateUrl: './home-page.component.html',
    styleUrls: (condition ? './home-page.component.scss' : './home-page.component-rtl.scss'),
    encapsulation: ViewEncapsulation.None
})
export class HomePageComponent implements OnInit {
    //....
}

But I’m getting an error error NG1010: styleUrls must be an array of strings.

I tried already to change the first line to another condition, ie: let condition = 1 + 1 == 2;, and the error didn’t show. It only shows when I use window.SOMETHING inside the condition.

As I investigate more, the error appears because window is undefined before the component loads.

How can I set the value styleUrls based on a condition depending on window.location.href value?
How can I access window before the component is loaded?

Integridade da Global window no JavaScript

Algumas ideias que se costumam usar para o código ser mais seguro (a primeira refere-se ao teu exemplo, e propriedades de window) :

  • regista como imutáveis as propriedades de window

No trabalho fizemos assim:

 const defineConstantProperty = function(key, value){
    Object.defineProperty(window, key, {
        value: value,
        writable: false,
        enumerable: true,
        configurable: false
    });
};

defineConstantProperty('propriedade', {% valor %});

e podes até testar isso no teu exemplo:

const defineConstantProperty = function(key, value, obj) {
  Object.defineProperty(obj || window, key, {
    value: value,
    writable: false,
    enumerable: true,
    configurable: false
  });
};

defineConstantProperty('console', console);
defineConstantProperty('log', console.log, console);

let oldLog = console.log;

console.log = function(message) {
  oldLog('CAPITURA')
  oldLog.apply(console, arguments);
};

console.log('teste')
  • usar IIFEs para evitar variáveis no escopo global (podes ler mais aqui)

  • usar const para evitar que variáveis sejam sobre escritas

  • usar let e const pelas vantagens do seu escopo de bloco

  • nunca confies no que vem do cliente, faz sempre verificação no servidor

  • evita ter informação sensível em URLs ou em variáveis, usa sempre indicadores (ids que podes usar no servidor) em vez da informação sensível

Is it good UX to prompt users before closing the browser window on mobile

i’m designing a mobile web based e-commerce solution. If the user closes the browser window, items in their cart will be lost (assuming they rejected the initial cookie request) when they return. To prevent this i’m considering prompting the user if they are sure they want to close the browser and would like to create an account . Is this a good way to overcome this issue or is there another way?

browser – “‘IDBIndex’ is not defined” in Edge Private window with VUE, Firebase

I am facing a very weird issue and I don’t know what is the root cause or how to investigate it further.

I created a simple website with VUE, initialized Firebase with firebase init, using Firestore to read/write some data, and using Cloud Functions for some background work.
That is all my site is doing. So far I’ve been testing on Firefox and everything was working fine. Today I tested on Edge and I noticed a very weird issue.

The site doesn’t display anything in Edge private window although its working fine in a non-private Edge window.

I am aware of inconsistencies across browsers, but I’ve never seen inconsistencies between private and non-private instances of the same browser.

I checked the console and noticed an error in the private window: ‘IDBIndex’ is not defined. I didn’t see this error in the non-private window.

Question:
What could be the possible reason for this inconsistent behavior between private/non-private window of the same browser?
How should I investigate/fix this?

Image1: Console on the non-private window, no error
Image1: Console on the non-private window, no error

Image2: Console on the Private window, error: ‘IDBIndex’ is not defined
Image2: Console on the Private window, error: 'IDBIndex' is not defined

websites – Cocoa: I can’t open new window or tab in Wkwebview

I’m a student making a web browser as a school project. I noticed a problem with my wkwebview. I set my web browser to open links in new windows but that didn’t work. I tried this code

 webView.configuration.preferences.javaScriptCanOpenWindowsAutomatically = true

But it doesn’t open links in a new browser. Also, I get the same problem with tabs too. When I click on a link that opens a new tab, It doesn’t open. I need help because this project is due very soon.

If this question is unclear to you, comment.

opengl – How do I render to a resizable window from a large fixed size back buffer in current graphics APIs?

I have some code that uses DirectX 9 with Windows native window management, that I would like to port to newer graphics APIs, but this code has a fairly unusual approach to window resizing, and it doesn’t seem obvious how to achieve the same things with newer graphics APIs.

The code I want to port allocates a back buffer large enough for a full screen window which remains the same size across window maximised, minimised, and resize events. When the window is smaller than the back buffer, only part of the back buffer is shown.

In order to render from this large back buffer, in DirectX 9, I’m specifying regions with the pSourceRect and pDestRect in IDirect3DDevice9::Present and using D3DSWAPEFFECT_COPY.

The advantages of this, as I see it, are as follows:

  • There’s no need to free and reallocate any resources in response to window size changes.
  • Not reallocating resources reduces code complexity significantly.
  • Not reallocating resources makes the application more responsive in the case of windows size changes.
  • The rendered scene continues to be drawn, smoothly, as the application window is being resized, without any need for potentially tricky and complicated attempts to update rendering settings in response to resize events.

(As the code is written, the application is essentially paused during window resize. The user nevertheless gets a smoothly updated view of the relevant part of the current static rendered scene during window resize.)

How do I do the same thing with newer graphics APIs?

In newer DirectX versions it seems like the ‘BitBlt model’ described on this page roughly corresponds to D3DSWAPEFFECT_COPY in DirectX 9:
https://docs.microsoft.com/en-us/windows/win32/direct3ddxgi/dxgi-flip-model

However, when I try setting the swap effect to DXGI_SWAP_EFFECT_DISCARD, in DirectX 12, I get the following error:
IDXGIFactory::CreateSwapChain: This D3D API version requires the swap effect to be one of DXGI_SWAP_EFFECT_FLIP_*.

So I guess the BitBlit model is no longer supported. 🙁

I guess a logical alternative would then be to do something equivalent ‘manually’, but it seems like doing something like this would lose one of the advantages of the trick, as it works out in DirectX 9, which is the smooth update during resizing without needing to intercept resize events and update stuff in response to these, in the application code.

What I’d like to see, ideally, are links to working code that does something equivalent to what I’m doing in DirectX 9, in DirectX 12, OpenGL, or Vulkan.

If it helps to see the code in action, and the resulting resize behaviour, you can see this in the PathEngine graphical testbed, which can be downloaded here: https://pathengine.com/downloads
(And I could also look at stripping out and posting source code for a minimal example application that demonstrates this behaviour, if this would help.)

javascript – I need help add my code to window focus function

My website has a download page, I created a count down the page & I need to add it window focus function, Here my code, please help me.

var window_focus;
var content = document.getElementById(&quot;container&quot;);
  content.style.display=&quot;none&quot;;
  setTimeout(function(){
    content.style.display=&quot;block&quot;;
  }, 10000);

</script>```

mail.app – “Move focus to next window” short cut toggling window order if I interact with a window

There is a very convenient keyboard short cut to go through all windows opened by the same application. For me (but it is not the same for everyone) it is Ctrl < to flip through the window in one order, and Ctrl > to flip backwards. So far so good.

The bug (I can’t think how it can be a feature), is that the order of windows is toggled as soon as I interact with one window. Let me explain with an example

  • I open Mac mail, I create (Cmd N) say 3 new windows with topic Draft 1, Draft 2, Draft 3. If I use Ctrl < it flips through Draft 2 Draft 1 Draft 3 etc… and Ctrl > flips in forward order

  • now I’m on Draft 2, I modify the title to be Super Draft 2. Now Ctrl < flips in forward order ! Draft 3 Draft 1 Super Draft 2 etc… (and Ctrl > backward) !

  • I can reproduce the bug with safari windows (not tab, really separate windows), so it looks like it is not specific to Mail

This is very inconvenient : I can have a dozen draft email windows opened, and I’d like to go through them systematically and possibly modify some. This bug forces me to toggle between Ctrl < and Ctrl > semi randomly in order to be sure I cycle through all windows.

I’m on Mac Book Pro with Catalina 10.15.4 but this behavior is there since I learned to use the toggle window shortcut, one or two years ago.