codespace icon indicating copy to clipboard operation
codespace copied to clipboard

Adds duck-based help50 - don't merge yet

Open dmalan opened this issue 2 years ago • 1 comments

TODOs

  • [ ] Remove backspaces from txt, as via col -b or sed
  • [ ] Handle ctl-A and ctl-E
  • [ ] Hide [1] Done... messages when backgrounded process ends, as with set +m
  • [ ] Hitting Enter alone at Bash prompt results in message to duck
  • [ ] Have Bash script exit early on any errors, as with set -e
  • [ ] Determine why ctl-d yielded below parent shell
Screenshot 2023-07-24 at 12 05 12 PM

How to Try

  1. Run:

     sudo apt update && sudo apt install -y colorized-logs
    
  2. Run:

    sudo wget https://raw.githubusercontent.com/cs50/codespace/help50/etc/profile.d/duck.sh -P /etc/profile.d/
    
  3. Open new terminal and run a command that yields a non-0 exit status (e.g., cd foo)

Screenshot

Screenshot 2023-07-22 at 11 16 51 PM

Implementation Details

  • Uses script command to capture all stdin/stdout/stderr in a temp file, so that it can optionally be accessed after a command runs.
  • Has access to (but doesn't currently use):
    • Specific argv run, from history
    • HTML-colored version of stdout/stderr, in case helpful for duck [currently using just text]
    • ANSI-colored version of stdout/stderr, in case helpful for duck [currently using just text]
    • $PWD in which command was run
    • File tree relative to $CODESPACE_VSCODE_FOLDER in case helpful for cd, etc.

dmalan avatar Jul 23 '23 03:07 dmalan

Works as expected. The only glitch I noticed is that the first error I did after opening a new tab did not trigger the ddb. Perhaps I was too quick?

/usr/bin/ld: /lib/x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x1b): undefined reference to `main'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [<builtin>: dictionary] Error 1
speller/ $ make dictionary
/usr/bin/ld: /lib/x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x1b): undefined reference to `main'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [<builtin>: dictionary] Error 1
[1]+  Done                    command50 ddb50.ask "$prompt"
speller/ $

did also notice that sometimes, the message send to ddb (and shown in the box) has unprintable chars overwriting some of it, like

Explain this error:
$ bavalgrind a valgrind: a: command not found

or

Explain this error:
$ jvalgrind valgrind: no program specified valgrind: Use --help for more information. 

The duck was still able to interpret correctly though.

edit to add I reproduced the "duck doesn't get the error" problem from before. It happens if the duck sidebar isn't already opened. I switched to the explorer, then had an error in the terminal. The duck sidebar opened, but the error message was never sent to it.

curiouskiwi avatar Jul 24 '23 09:07 curiouskiwi