loh-tar / cpd

A pure bash script to collect copy jobs and start them only if the target drive is not busy by any other job under supervision of cpd
GNU General Public License v2.0
2 stars 1 forks source link

Blank status output on Eshell #4

Closed Ambrevar closed 6 years ago

Ambrevar commented 6 years ago

I haven't investigating but right now I get the following on Eshell (the Emacs Elisp shell):

> ./cpd -D
No running daemon
Job list:

While I get this with bash:

No running daemon
Job list:
 ID PRIO STATUS   SIZE  DRIVE            TARGET                FILES
  7   5  pending  4.4K  /dev/sda         ~home/ambrevar/temp'  'README.md'
  2   7  pending   13K  /dev/sda         '/media/a/foo'        '/media/data/bar
  1   9  done     7,5K  /dev/sda         '/media/a/foo'        '/media/data/foo
  3   9  NOSTART  6,2K  /dev/sdd         '/media/d/foo'        '/media/data/raz
  4   9  done      19K  luks-as2dws34xy  '/media/luks/foo'     'data1'
  5   9  canceled 5,2K  luks-as2dws34xy  '/media/luks/foo'     'secret stuff' '
  6   9  killed   2,6K  /dev/sdc         '/media/c/foo'        'cpd' 'cpd1'
loh-tar commented 6 years ago

Whew! I'm sorry, I know nothing about Eshell :-)

But you know where the daemon is searched, in getDaemonPid() Now, when I look at there, probably the way how the pid is read is problematic?

daemonPID=$(< "$tmpDir/daemon-pid")
Ambrevar commented 6 years ago

OK, I had the same problem before with https://github.com/ambrevar/demlo: this is because Eshell is a "dumb" terminal and stty returns "0 0". The fix is easy:

  screenWidth=$(stty size|cut -d' ' -f2)
  [ $screenWidth -eq 0 ] && screenWidth=$COLUMNS
  [ $screenWidth -eq 0 ] && screenWidth=$COLS
Ambrevar commented 6 years ago

Also to answer your question in the comment of setScreenWidth: stty is a good way to get the size of the terminal. tput cols also works if you assume ncurses is installed. Because of dumb terminals, you should fallback on COLUMNS and COLS (not sure the last one is ever necessary).

Ambrevar commented 6 years ago

Better fix, actually:

  screenWidth=$(stty size|cut -d' ' -f2)
  [ $screenWidth -eq 0 ] && screenWidth=$COLUMNS
  [ $screenWidth -eq 0 ] && screenWidth=$COLS
  [ $screenWidth -eq 0 ] && screenWidth=72

It's better to have screenWidth default to some value, even if it does not wrap well, than not displaying anything at all.

loh-tar commented 6 years ago

I have tried to fix one more issue (cut nothing when not on terminal) but that was too much. Any idea how to solve this?

#FIXME: Works to good (when using watch ) :-S
if [[ -t 1 ]] ; then
  screenWidth=$(stty size|cut -d' ' -f2)
  # Some dump terminal like Eshell ask for special treatment
  # https://github.com/loh-tar/cpd/issues/4#issuecomment-346942540
  (( screenWidth )) || screenWidth="$COLUMNS"
  (( screenWidth )) || screenWidth="$COLS"
else
  # Some big enough number which will not cut some output line
  screenWidth="999"
fi
Ambrevar commented 6 years ago

What's the issue?

Note: It's "dumb" terminal, not "dump".

loh-tar commented 6 years ago

What's the issue?

It's better to have screenWidth default to some value, even if it does not wrap well, than not displaying anything at all.

How about 999 instead of 72?

Conclusion: stty can somehow detect that there is a terminal when running with watch, at least does it report the correct setting.

Ambrevar commented 6 years ago

It depends on what cpd does after screenWidth: does it wrap or does it truncate? From what you are saying, I assume it truncates, which is why you want 999, right?

Then by all mean, go for a big truncate value.

Ambrevar commented 6 years ago

Thanks!