I would like to write 80 (standard conole width) characters in one line without the cursor go to next line. It is only problem when I want to print 80 characters in the last line of console. It cases scrolling that I dont want.
Take a look:
I dont want the newline. any way to do this? :/
Im on Windows, DEV-C++, using WinApi for colors and moving the cursor (the window resize too).
Thanx for any answers.
Instead of using standard output functions use the Windows Console API to set the cursor position and draw characters. Specifically, take a look at WriteConsoleOutput.
MSDN Console API Docs
The only reason why you are on a new line is because the console is not big enought to support the eighty stars.
So it pushed the cursor to the next line.
through one or two "\b" at the end it moves the cursor back.
For the system-critical console window, the cursor should always stay visible, and the only way for it to do so after you've reached the max number of chars in a line, is to pop up on the next visible line (without actually making any new lines).
filter the output either in the originating program or with another program through a pipe. When you have outputted too many characters on a single line, do whatever you like (i.e., drop characters, overwrite, etc....).
Related
So I've outputted a string of various ASCII characters. This program involves parts of this string being modified, and then re-displayed.
Instead of clearing the entire screen and re-displaying everything, which produces an unwanted flicker effect, I've decided on moving the cursor and then rewriting only the characters that have changed.
I'm moving the cursor with SetConsoleCursorPosition, part of windows.h.
However, once I try and cout something, it pushes all of the text in front of it ahead by a space; another unwanted effect.
In an attempt to fix this, I tried various forms of 'cout<<"\b";' to remove the old, unmodified character. But there was either no effect, or it actually added a space, which is obviously not a desired effect here.
I read somewhere that in order to remove the unwanted character that you actually have to use the escape sequence twice, Example: '\b\b', because the first one moves the cursor back a space, and the second one overwrites the character in front of it with a space (' ') or something like that.
'\b\b' didn't work either, unsurprisingly. Or maybe that is surprising, I don't actually know.
My question is: How do I remove the unwanted character? Or better yet, How do I overwrite text that has already been outputted with new text?
EDIT: I apologize, I'm running Windows 7
I think maybe clearing the ENABLE_INSERT_MODE with the SetConsoleMode function might help. It should prevent the console from inserting characters and pushing the old characters forward.
I am building a part of a tower defense game in a strictly console environment and i am stuck at the moving of a creature lets say "c", i would like the letter "c" to start on the left and move a space at a time to the right on the same line basically:
c (one second later)
c (one second later)
c and so on....
i thought that this could be implimented with an array but am lost, i want to be able to use simple code, not weird libraries and weird methods, just simple as possible. Thank you
One method is display all the characters, then a carriage return ('\r') and then reprint the line.
This allows you to "walk" characters across. This will only work on video terminals that do not advance a line upon receiving a CR.
Another method would be to print 10 backspace characters, a space, then your 10 'c'. This may not be as fast as the carriage return method above, but worth looking at.
As others have said, you may want to look into a terminal library such as ncurses. The library allows you to position the cursor on the screen, based on the terminal type. This may require setting up the console window to emulate a terminal.
It seems that you can go back one character from current line in the console using \b. However, the console doesn't seem to be able to jump one line up.
I want to mark invalid user input red. After typping input, user presses Enter which put's unerasable new line in the console.
My plan was to do the following:
Check the input for validity.
If it's invalid, print input.length()+1 times \b
Turn console color red
Print the input, print \n
But, the \b will not jump back to the line where user input is. So I have plan B:
Remember the length of string that was before user input (query_string)
Check the input for validity.
If it's invalid, go line up (where the input was entered)
Jump to query_string.length() character
Turn console color red
Print the input, print \n
However, I don't know how to do this using the console API.
There are at least two ways you can do this.
One way is, as #chris implied in a comment, is to save the cursor position of where the user started typing. When you find bad input, you set the cursor back to that position and change the text attribute of the characters he entered.
You probably don't want to scroll the window back up one line. If you do, then the window will appear to "jump" when the user makes an error. It's a really jarring user interface experience. But if you want to try, you can call ScrollConsoleScreenBuffer.
Another way to do it would be to change the console mode so that it doesn't automatically echo characters when the user types them. Instead, you read each character individually, append it to your input buffer, and when the user presses Enter you validate. If the input is valid, you issue a newline to move to the next line. Otherwise you back up and highlight the erroneous input. This sounds like a lot more work, but it's not that difficult and it results in a much better UI experience.
I have a file containing (hundreds) of blocks of numbers like below;
This one is fine (16x20, correct number of rows and columns)
11111111111111111110
16666616666666661110
16111616111111162610
16111646111663132610
16162616261623132610
16162313261623132610
16162313261623132610
16162313261623132610
16162313261623132610
16162313261623132610
16162313261623132610
16162313261626132610
16166313661116632610
16111111111116132610
16666666666666136610
11111111111111111110
This one needs to be padded with trailing zeroes so it is (16x20)
111111111111111111
166616666666663661
166611111111111661
166666366663661661
113161111111161611
1316166666616161
1616162262616161
11616166112616161
16616166116616161
16616162262616161
16616166266616161
16616111161116161
1661666666666616111
1661666166163366661
1641666166166613661
1111111111111111111
I would like to pad them with zeroes so they are all like the first example. I'm aware of the regular expressions feature in notepad++ but am struggling to get it to work. I appreciate any help given.
You could do it via a macro.
First append a large number of zeroes to the end of each line using a macro.
Caret on the first entry
click record macro
press end
type out 20 zeroes
press down arrow
click stop recording
play the macro until all lines look like this
11111111111111111100000000000000000000000000000000000000000000
16661666666666366100000000000000000000000000000000000000000000
16661111111111166100000000000000000000000000000000000000000000
16666636666366166100000000000000000000000000000000000000000000
11316111111116161100000000000000000000000000000000000000000000
131616666661616100000000000000000000000000000000000000000000
161616226261616100000000000000000000000000000000000000000000
1161616611261616100000000000000000000000000000000000000000000
1661616611661616100000000000000000000000000000000000000000000
1661616226261616100000000000000000000000000000000000000000000
1661616626661616100000000000000000000000000000000000000000000
1661611116111616100000000000000000000000000000000000000000000
166166666666661611100000000000000000000000000000000000000000000
166166616616336666100000000000000000000000000000000000000000000
164166616616661366100000000000000000000000000000000000000000000
111111111111111111100000000000000000000000000000000000000000000
Then...
Caret on first line
click record
press home key
press the right arrow key 20 times
hold shift and press end key
press delete key
press down arrow
click stop recording
play the macro until all lines are processed
You could save the entire process as a single macro so its just a single click in the future.
I can give you a macro solution
go to the beginning of your text
select Macro/Start Recording
press end, press 0 16 times then press Home and down arrow key
select Macro/End Recording
You now have a macro to add sixteen zeros to the end of all lines.
Playback this macro on all lines.
You now have appended zeroes to all lines.
Pressing Alt key and using mouse select the required block(columns) of text you want and paste it into another empty notepad tab
help on column mode editing is there inside notepad ? / help contents menu
Good luck
You can use the plugin ConyEdit to do this.
With ConyEdit running in the background, follow these steps:
use the command line cc.aal 00000000000000000000 to append after lines with twenty zero character.
use the command line cc.gc 1/\d{20}/ to get the first column of regex match.
Looking to do this manualy and not progomaticly ?
Open Findreplace
Copy from the last to rhe first WITHOUT NUMBERS on a line so...
in this example
111111111111111111 <---from here
to here ---> 166616666666663661
166611111111111661
paste that into the fine ( yes your effecticly copying the return wich some applications allow you to manualy input others wont )
then in the replace box, type '0' then your return
Hit that magic replace all :D
This will then add a 0 every time it hits a new line, then add a new... new line....
edit : quickly reviewing another method a second to recover for alternate options :P give me 10
edit 2:
Ah ok somthing like this will work :P just tested it.
use [0-9] in the find replace. so if im looking for 123123123123 ( wich is 12 long ) and i need to buff i up to 20,
Your FIND must be in ()
so..
the find would be
([0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9] )
and the replace is referd to as \1 no the regex, this was my mistake
\100000000
tested and confirmed !dont forget YOU NEED MATCH ALL on, WRAP off!
And so on for your other numbers, Not sure if you can loop this with macros nd stuff :P but hope it helps more than you have now
two good resources.
http://blog.creativeitp.com/posts-and-articles/editors/understanding-regex-with-notepad/comment-page-1/
http://regexpal.com/
base on OP's comment: you could try an editor called vim/gvim
open your file in vim, then type:
:%s/.*/\=printf("%-20s",getline("."))/|%s/ *$/\=substitute(submatch(0)," ","0","g")/
don't forget pressing <Enter> after the above typing.
then you will see the text has been changed into what you want.
of course vim macro can work as well, however, I feel command better... :)
I'm making a game gui api and I'm wondering how to implement tabs. I'm using freetype for text. When I try to render '\t' It looks like a square. I'm wondering how tabs are implemented because they are not a fixed width.
Thanks
For a fixed-width font you could compute how many spaces to the next tab stop, but the general solution is to stop rendering when you hit a tab, move to the next tabstop, and then render the text that comes after the tab character starting from there. Where the tabstops are is up to you, but a good default is probably something like every 8 ems.
The simplest strategy is to swap a tab out for a some number of spaces. I.e. when the user pushes tab, pretend they pushed tab four times instead. (Or just print out four spaces, whatever works for you)