Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9142201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:44:46+00:00 2026-06-17T09:44:46+00:00

I just made a little chat CLI-application that works pretty fine actually! Unfortunately, when

  • 0

I just made a little chat CLI-application that works pretty fine actually!

Unfortunately, when one types a message and receives other’s messages at the same time, both interlacing… Which renders quite awful:

elton: Hey!
john: how are you doing?
fine anjohn: still not to bed?!
d john: haha
you?elton: fine and you?

I’m looking for a way to avoid this kind of problem. Such as “reserving” the last line for user-input or process some actions when data are received to recalculate the position of user-input.

After some research I found that I shall retrieve each character one by one with getch(). So that I can check regularly if a new message is waiting to be displayed and handle this case.

But if I use getch() I have to redefine manually basic actions (such as backspace, move left and right…), some characters take more than one byte. In brief, it’s unusable.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:44:47+00:00Added an answer on June 17, 2026 at 9:44 am

    As far as I can tell, you have a few options here. Normally just calling getch you’re running the terminal in what’s called “cooked” mode. This means that the terminal just displays characters in the order they arrive, nothing too special. However you run in to race conditions as you’ve discovered.

    Option 1: you read things in one character at a time, buffering the entire line. When a new line arrives and you want to print it out, you’d have to (a) grab hold of some kind of print mutex (internal to the program), (b) clear out the current line (print ‘\r[space][space][space]…\r’), (c) print the incoming line + ‘\n’, and (d) restore the previous buffer to the screen (via print) and unlock the mutex.

    This gets ugly. Fast. As you discovered, there’s no line editing support or anything fancy. The only good thing about this approach is that it’ll probably work in about 99% of terminals.

    Option 2: you put the terminal in to raw mode. In this mode, you have complete control over the terminal, but you lose very basic functionality (e.g. typing a key won’t display it unless you manually output it). You would still have to manually implement things like navigation, but at least it would work. This method is probably the most flexible and give you the most control, however it’s very difficult to work like this, which is why they invented…

    Option 3: you use ncurses (or a similar terminal library). The concepts are a little difficult, but FAR easier to learn than doing things in pure raw mode. Editing and windowing (or as you put it, reserving a line) are built-in. The interface can be much prettier than you’d get from cooked mode.

    EDIT I’m talking a lot about *nix terminals here, most of which doesn’t apply for Windows.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just made my first proper little desktop GUI application that basically wraps
I've just made a little test with loops in Java. I assumed that the
I have a silly little game that I made just for myself, but I
I've just started learning Objective-C and made a little compass app that will display
I just made my first website , and I notice that the elements start
I was just made aware of a bug I introduced, the thing that surprised
I have an image which is just made of one color ? (it could
I've just made a little server amf on gae and pyAmf ( now down?).
So I have made a little piece of code that will insert and manipulate
I'm using AngularJS and I have a little question here. I just made my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.