xmessage long text - wrap? - linux

I want to use xmessage (it is the only available in the release I am using sorry) to display a message to the user. The message is a bit long and does not fit in one line. xmessage displays the message in one line up the point that is visible.
Is there any way to automatically wrap the text?
I tried the trick to
echo -e " message line 1 \n message line 2" | xmessage -file -
BUT because my message is coming from a variable and I want to also use it in my logger I do not want to use the "\n" in it. Do I have any chances?

You can pipe the text through fmt.

Related

Fish shell custom function for output text coloring

When using fish shell in a terminal-emulator (such as terminator) together with a command that outputs lots of text it could be useful to get some color coding on the output. I know that a script can add color code information to the output like "grep --color=auto". I guess it's possible to modify the fish terminal to scan through the output and add this in special places?
What I want to do is that the text "error" appearing in the output from any script always is marked red and that "warning" always is marked yellow. Anyone knows if this is possible by introducing function files in the ~/.config/fish/functions dir or similar?
This is basically a layering violation. Usually the output of external commands does not go back through the shell. It goes directly to the terminal.
Also, anything you do here has the potential to slow output down. (And because of fish issue #1396, this can be rather extreme).
That said, it's possible if you always pipe to a function like this
function colorstuff
while read -l input
switch $input
case "*error*"
set_color red
echo $input
case "*warning*"
set_color yellow
echo $input
case "*"
set_color normal
echo $input
end
end
set_color normal
end
Use it like somecommand | colorstuff. (And maybe add 2>&1 if you also wish to have stderr colored)
In my tests, this causes a noticeable slowdown, and even with that issue fixed it will still be slower since it has to match every single line.
Really, the real solution is for whatever tool you are using to color itself, since it knows what the output means. All this can do is look for keywords.
For general output colorization needs, I added the grc plugin to Tackle for precisely that purpose.

Vim printing text at the bottom after executing a command

What I am trying to do is to give visual feedback that I have done something . For example, if I mapped a key to do a git pull and refresh, and I want to say something like "Files reloaded"
What function should I use in VIM to print the text in the little line at the bottom after I execute my function? I'm talking about the line at the bottom that says "recording" when you type in 'q'. If it's not possible (maybe it's reserved from vim only), is there another way to do this?
Try echo or echom (see their help entries for the difference).

How do I prevent long emails from becoming attachments?

When a build finishes, the bash script calls:
nail -s "Build completed" $towhom < buildreport
When the buildreport is over 2,000 characters long, it arrives as an attachment.
Where can one set the threshold for the size of the body becoming an attachment?
Based on the comment from ottomeister, There are a lot of reasons why the mail would be autoconverted to an attachment by nail
Individual lines are too long (>950 characters)
There are control characters in the message
If the message is UTF-8, then it seems as though it gets properly parsed (but this is only based on code from on-line, which may not be what you're using)
You could probably run the content of the file through a filter - e.g. to remove all non-ascii characters:
tr -cd '\11\12\15\40-\176' <buildreport | nail -s "Build completed" $towhom
... but that will clobber all UTF-8 characters
If you want to get the log input to wrap at 1 number of characters, then you can use a perl one-liner like:
perl -e 'use Text::Wrap; print wrap("", " ", <STDIN>);' < buildreport | nail -s "Build completed" $towhom

Dynamic Bash Script (i.e top)

I'm wondering if there is a method to have a bash script present data to the console and consistently update it. Much like the functionality of top, but in a more simple form.
watch -n 1 <your-command>
From the watch(1) man page:
Execute a program periodically, showing output full screen
You need to use curses for this. Here's one detailed article about curses usage.
You can use "while true / clear"-loops to have constantly updated screen like:
#!/bin/bash
while true
do
clear
echo "your output"
uptime
sleep 5
done
You can use terminal escape codes. You can print them with echo -ne (drop the n if you want the newline afterwards). The escape character is \033. This will clear the screen and put your cursor at the top left:
echo -ne "\033[2J\033[f"
There are cursor-positioning codes, color codes, formatting, etc.

How do I erase printed characters in a console application(Linux)?

I am creating a small console app that needs a progress bar. Something like...
Conversion: 175/348 Seconds |========== | 50%
My question is, how do you erase characters already printed to the console? When I reach the 51st percentage, I have to erase this line from the console and insert a new line. In my current solution, this is what happens...
Conversion: 175/348 Seconds |========== | 50%
Conversion: 179/348 Seconds |========== | 52%
Conversion: 183/348 Seconds |========== | 54%
Conversion: 187/348 Seconds |=========== | 56%
Code I use is...
print "Conversion: $converted_seconds/$total_time Seconds $progress_bar $converted_percentage%\n";
I am doing this in Linux using PHP(only I will use the app - so please excuse the language choice). So, the solution should work on the Linux platform - but if you have a solution that's cross platform, that would be preferable.
I don't think you need to apologize for the language choice. PHP is a great language for console applications.
Try this out:
<?php
for( $i=0;$i<10;$i++){
print "$i \r";
sleep(1);
}
?>
The "\r" will overwrite the line with the new text. To make a new line you can just use "\n", but I'm guessing you already knew that.
Hope this helps! I know this works in Linux, but I don't know if it works in Windows or other operating systems.
To erase a previously printed character you have three options:
echo chr(8) . " "; echoes the back character, and will move the cursor back one place, and the space then overwrites the character. You can use chr(8) multiple times in a row to move back multiple characters.
echo "\r"; will return the cursor to the start of the current line. You can now replace the line with new text.
The third option is to set the line and column of the cursor position using ANSI escape codes, then print the replacement characters. It might not work with all terminals:
function movecursor($line, $column){
echo "\033[{$line};{$column}H";
}
\r did the trick.
For future reference, \b does not work in PHP in Linux. I was curious - so I did a couple of experiments in other languages as well(I did this in Linux - I don't know if the result will be the same in Windows/Mac)..
\b Works in...
Perl
Ruby
Tcl - with code puts -nonewline "Hello\b"
\b Doesn't work in
PHP - the code print "Hello\b"; prints out Hello\b
Python - code print "Hello\b" prints out Hello<new line> . Same result with print "Hello\b",
I'm not sure if it's the same in Linux but in Windows console apps you can print \r and the cursor will return to the first left position of the line allowing you to overwrite all the characters to the right.
You can use \b to move back a single character but since you're going to be updating your progress bar \r would be simpler to use than printing \b x number of times.
This seems to be pretty old topic but I will drop my 5 into.
for ($i; $i<_POSITION_; $i--) {
echo "\010"; //issue backspace
}
Found this on the internet some time ago, unfortunately don't remember where. So all credits goes to original author.
to erase a previously printed character, I print a backspace after it:
print "a"
print "\b"
will print nothing (actually it will print and then a backspace, but you probably won't notice it)

Resources