1

My cout statements don't print correctly on my terminal for some reason. It creates space. When I have the following code:

void Test::testSorted(){
   vector<int> unsorted = {4, 6, 5, 2, 1, 3};
   vector<int> sorted   =  {1, 2, 3, 4, 5, 6};

   cout << "Testing isSorted function for unsorted Pancake ... : " << endl;
   game.setPancakeStack(unsorted);
   bool condition1 = game.isStackSorted(); 

   cout << "Testing isSorted function for sorted Pancake ... : " ;
   game.setPancakeStack(sorted);
   bool condition2 = game.isStackSorted(); 
}

The terminal exactly outputs this with the exact amount of space:

Testing isSorted function for unsorted Pancake ... : 
                                                     Testing isSorted function for sorted Pancake ... :

NOTE: I have been using ncurses for a project and I feel like that might have messed up my shell. But I don't know where to even look to fix this issue

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
Pape Traore
  • 83
  • 2
  • 9
  • If you're worried your shell is messed up, did you try exiting the shell and running this in a new one? – scohe001 Nov 02 '18 at 15:39
  • 4
    If you kill or exit a curses application without letting it clean up properly, then yes you can get such problems. If the curses program is yours, then make sure you clean up after yourself, and exit cleanly. – Some programmer dude Nov 02 '18 at 15:40
  • Also are you sure there's nothing in your functions that could be printing whitespace? Have you tried commenting everything and only running the output statements to make sure it **is** in fact your terminal? – scohe001 Nov 02 '18 at 15:44
  • Yes I have tried to comment everything out and print stuff and it is giving me those white spaces – Pape Traore Nov 02 '18 at 15:49
  • you might have been cursed ;). Can you provide a [mcve]? Currently we can only guess what is the problem. Maybe first try to reproduce in a fresh shell... – 463035818_is_not_an_ai Nov 02 '18 at 15:52
  • Is there any printing in `setPancakeStack()` or `isStackSorted()`? – Thomas Matthews Nov 02 '18 at 15:56
  • Looks like you may need to adjust your terminal to print `CR, LF` when receiving `LF`. – Thomas Matthews Nov 02 '18 at 15:56
  • How do you do that? – Pape Traore Nov 02 '18 at 16:02
  • standard output on terminal when `ncurses` is used is a strange mix, which may lead to this strange effects. Your application should print directly to console using `ncurses` xor print standard output associated with console. – Marek R Nov 02 '18 at 16:09
  • 1
    The question does not make it clear whether the code is part of the ncurses application or the ncurses thing was something unrelated before and now you are just looking to uncurse your shell. If it's the latter, the command line utility `reset` should help. –  Nov 02 '18 at 16:27
  • In your shell, you can try `stty sane` to get it back to some semblance of proper behavior. If that doesn't work, you'll probably need to quit your shell and start a new one. – Eljay Nov 02 '18 at 18:42

1 Answers1

1

This symptom is a textbook case of an ncurses application not quitting properly and leaving the terminal in the wrong "mode". Just open a new terminal to fix it.

If the ncurses application did quit cleanly, it's missing some deinitialisations (endwin()?) at the end of main, which is either for you to fix (if you wrote the application) or for you to report to the developers (otherwise).

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055