Resizing output Terminal in C Language - c

would like to get some help on a c project i am currently working on. I have a string/array of output to the terminal, but somehow the standard terminal is too small for my output. Even after i manually expand the window of the console the output is still cut off, instead of printing in a single line, it just gets cut off and go to the next row automatically.
hope to get help.

I think that the only way to correct this is by splitting your one-line output in multiple lines, using "\n" at the end of every line.
By doing this you can control when and where it has to write in the next line, and you can make it look more like you wanted to.

Related

Trouble with Scilab "print" instruction

Trying to debug a program in Scilab, I inserted a couple
of "print" instructions to track what is going on.
At first, I used the %io(2) output "file" which, according
to the Help, stands for the console. Nothing happened.
Then I used an actual filename:
print("C:\Leszek\Xprmnt\scl\Ovsjanko\K3ScilabLog.txt", "START! \n \n \n \n GOING \n")
which does print to that file, but when the dust has settled
and I want to inspect the file what I find inside is just the last
message (just before the program crashed), even though there should
have been others before it, including the "START" etc in the quote above.
Apparently, every print command reopens the file for writing as a clean slate,
overwriting whatever was in it before. Looking into Help and online docs
I didn't find any options or parameters that I could use to change this.
What I want is, obviously, the output from all my print commands since the
beginning of the program, either on the console or in a text file.
TIA.
Just use disp("some text") or mprintf("format",var1,...,varn), both will display on the console. If you need to write in a file use fd = mopen("file.txt") then mfprint(fd,"format",var1,...,varn).

Delete current terminal input line

I am trying to code a little console chat-program in C on linux.
So far I coded it in a way that both chatting partners are only able to alternately send/recv, because these function calls are blocking by default.
Now I would like to modify that program, so that both are able to send and receive simultaneously.
The problem that I find is, that once you typed some input to the terminal, I don't know how to output received messages, without messing up the current input line of the terminal.
If there was a way to delete that current input line, you could temporarily save that line, print the new message and put the input line right back.
However, I was not able to find a solution for this problem on the internet.
Is it possible to delete the current input line, and if not, how else could I achieve what I want?
I think you should look into ncurses as Edd said in his comment.
It would allow you to easily manage contents in your terminal window, which sounds like a good idea for your chat program.
All you'd need to do is store your messages in 2 character arrays:
char incoming[MSG_MAX]
and
char outgoing[MSG_MAX]
Then you can output those messages wherever you want in your terminal window, since ncurses allows you to specify x,y coordinates on where to put your text.
Then a simple wrapper for one of ncurses erase() family functions would allow you to delete characters from specify x,y coordinates in your terminal window.
Edit: MSG_MAX is not an actual ncurses macro.

C escape sequence \033[999D not working properly

I'm trying to use the escape sequence \033[999D as a brute-force way of moving the cursor to the top row in the console. When I run my program, rather than doing what I intend, it returns a left-pointing arrow and a [999D, on the same line that I was last on.
How should I properly use this escape code? Are there any (better) substitutions?
My (test) code:
printf("This is a line\n");
printf("This is another line\n");
printf("\033[999D Overwrite");
My output:
This is a line
This is another line
←[999D Overwrite
Check out the Win32 Console API.
Particularly of interest to you:
GetStdHandle (MSDN)
SetConsoleCursorPosition (MSDN)
Here is an example showing how to move the cursor to a specific position.
Here is an example showing how to clear the screen.
Of interest to people looking to set console colors:
SetConsoleTextAttribute
There are two problems (most likely): The first is that the D VT100 cursor control sequence is to go back a number of columns, which means it will go back a number of columns on the current row. It will not change line.
The second and the likely problem the code is printed is because you probably are using the Windows console program (the "DOS prompt") which is very bad at handling VT100 sequences by default.

Ubuntu terminal not displaying all values

I have a C program that displays all the possibilities of the letters "A-B-C-D-E-F" can make. That comes to 720 possibilities. But my terminal is only displaying 511 possibilities. I tried looking online on how to edit terminal settings and found this following and did them. I went into edit>profile preferences and selected "use custom terminal size" and set both the values for rows and columns to 800. Sadly only 511 continues to display.
Can someone please tell me what is the solution to this, im really puzzled.
PS: Every entry is on its own line. For example:
ABCDEF
ABDCEF
......
......
In addition to less described by David Grayson, you should also be familiar with redirection:
my_program > outputfile.out
This creates a new file (or overwrites an existing one) with the output from your program. Now you can open the file in a text editor to look at the output. You can also use the wc utility to count the number of lines:
wc outputfile.out
If you only want to check that your program creates the correct amount of output, you can use the following pipe:
my_program | wc
You need to go to the Scrolling tab and set the number of lines in scroll buffer to something higher than 512.
Another useful utility to know about is less. You can pipe the output of your program into it and it lets you scroll around and search through the output:
my_program | less
I think you want to see all the output answers.you can see the answer from "answer" after you execute the program like a.out>answer.
now open the file(answer),you will see the result.
">" is a operator

Stable text feed for vim through vimserver

I am searching for a highly stable way to feed text (output of a program) into vim through vimserver. Assume that I have started a (g)vim session with gvim --servername vim myfile. The file myfile contains a (unique) line OUT: which marks the position where the text should be pasted. I can straight forwardly achieve this from the commandline with vim --servername vim --remote-send ':%s/OUT:/TEXT\\rOUT:/<Enter>'. I can repeatedly feed more text using the same command. Inside a C-program I can execute it with system(). However TEXT which is dynamic and arbitrary (received as a stream in the C-program) needs to be passed on the command line and hence it needs to be escaped. Furthermore using the replacement command %s vim will jump to the position where TEXT is inserted. I would like to find a way to paste large chunks of arbitrary text seamlessly in vim. An idea is to have vim read from a posix pipe with :r pipe and to write the the string from within the C-program to the pipe. Ideally the solution would be such that I can continuously edit the same file manually without noting that output is added at OUT: as long as this location is outside the visible area.
The purpose of this text feed is to create a command line based front end for scripting languages. The blocks of input is entered manually by the user in a vim buffer and is being sent to the interpreter through a pipe using vim's :! [interpreter] command. The [interpreter] can of course write the output to stdout (preceded by the original lines of input) in which case the input line is replaced by input and output (to be distinguished using some leading key characters for instance). However commands might take a long time to produce the actual output while the user might want to continue editing the file. Therefore my idea is to have [interpreter] return OUT: immediately and to append subsequent lines of output in this place as they become available using vimserver. However the output must be inserted in a way which does not disturb or corrupt the edits possibly made by the user at the same time.
EDIT
The proposed solutions seem to work.
However there seem to be at least two caveats: * if I send text two or more times this way the `` part of the commands will not take me back to the original cursor position (if I do it just once still the markers are modified which may interrupt the user editing the file manually) * if the user opens a different buffer (e.g. the online help) the commands will fail (or maybe insert the text in the present buffer)
Any ideas?
EDIT: After actually trying, this should work for you:
vim --servername vim --remote-send \
":set cpo+=C<CR>/OUT:<CR>:i<CR>HELLO<CR>WORLD<CR>.<CR>\`\`"
As far as I can see, the only caveats would be the period on a single line, which would terminate :insert instead of being inserted, and <..> sequences that might be interpreted as keypresses. Also, need to replace any newlines in the text with <CR>. However, you have no worries about regular expressions getting muddled, the input is not the command line, the amount of escaping necessary is minimal, and the jumping is compensated for with the double backticks.
Check out :help 'cpoptions', :help :insert, and :help ''.
Instead of dealing with the escaping, I would rather use lower-level functions. Use let lnum = search('^OUT:$') to locate the marker line, and call setline(lnum, [text, 'OUT:']) to insert the text and the marker line again.

Resources