Lock invitation at bottom of screen

everything. I am writing a chat client in Go as proof of the concept of the library that I find in the writing process. It should receive user data and print incoming messages in one terminal window. Consider the following.

user@debian ~ $ ./client no session> 192.168.1.100 > Hello, there! Hi! > So, did you get that feature working yet? Nope. I thought you were going to ask on StackOverflow. >> Yeah, I'm aski 

If another message appears while entering another message, it should contain the following.

 user@debian ~ $ ./client no session> 192.168.1.100 > Hello, there! Hi! > So, did you get that feature working yet? Nope. I thought you were going to ask on StackOverflow. Or did you want me to? >> Yeah, I'm aski 

Is there any way to do this in Go?

Thanks:)

+4
source share
2 answers

If you have ever used a console application that behaves like this, you probably used a library like ncurses for this. You do not want to program yourself, because it is quite difficult.

For Go, I would recommend termbox-go . It is easy to pick up and has a well-structured api .

+4
source

This may not be the right way to do this (not a console developer), but some time ago I did a terminal animation in Go that I ran on my Android phone. This is done by cleaning the screen, drawing, cleaning, etc.

I don’t remember what I used to clear the screen, but for example, I just tried this, fmt.Print("\033[2J") and it seems to work. Caution should be exercised here. Support for escape sequences to clear the screen may differ for the platform and even the terminal emulator.

But keeping in mind, you could keep a buffer of what the client should look like when a message is received, clear the screen, and then change and retype the buffer.

0
source

Source: https://habr.com/ru/post/1447363/


All Articles