canonical / craft-cli

https://canonical-craft-cli.readthedocs-hosted.com/en/latest/
GNU Lesser General Public License v3.0
9 stars 15 forks source link

messages: allow to set the terminal window title #160

Open sergio-costas opened 1 year ago

sergio-costas commented 1 year ago

This patch allows to set the text in the title of a terminal window. The idea is to allow snapcraft to set in the title which step is currently doing.

This is a first proposal for https://github.com/canonical/craft-cli/issues/159

codecov[bot] commented 1 year ago

Codecov Report

Merging #160 (04c2c41) into main (91c4b88) will increase coverage by 0.04%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #160      +/-   ##
==========================================
+ Coverage   94.62%   94.66%   +0.04%     
==========================================
  Files           7        7              
  Lines        1042     1050       +8     
  Branches      190      193       +3     
==========================================
+ Hits          986      994       +8     
  Misses         53       53              
  Partials        3        3              
Files Changed Coverage Δ
craft_cli/messages.py 100.00% <100.00%> (ø)
craft_cli/printer.py 100.00% <100.00%> (ø)
sergio-costas commented 1 year ago

Ok, you can use https://github.com/snapcore/snapcraft/pull/4217 to test this.

sergio-costas commented 1 year ago

@tigarmo I forgot to change this from draft to ready. Done.

tigarmo commented 1 year ago

Thanks. I'll try this out and give you feedback today

tigarmo commented 1 year ago

I did some experimenting and found a couple of problems:

1) The escape code to set the window title doesn't work on default Konsole. It does work on xterm. Which terminal are you using? I can get it to work on Konsole if I change the "Tab title format" option to %w: image I wonder if there's a "more portable" way to do this.

2) The last set title persists after Snapcraft exits. See the end of this gif: craft-cli-window-title we should clear that up, ideally restoring the original title but I don't know how feasible that is.

sergio-costas commented 1 year ago

I'm using Terminus, which uses VTE.Terminal class inside. The codes that I use in the patch are the XTerm ones, yes... https://tldp.org/HOWTO/Xterm-Title-3.html

Can you test this?

imagen

it seems that it's the ANSI code for Konsole...

About preserving the title... yes, you are right. I didn't implement that because, in my case, it already does that due to a script that I have for GIT, but it should be preserved and restored. I'll try it.

sergio-costas commented 1 year ago

I'll try changing the ANSI command from 2 (set the title) to 0 (set the title and the icon) just in case...

sergio-costas commented 1 year ago

Sent a bug report to KDE about the Konsole problem: https://bugs.kde.org/show_bug.cgi?id=471353

sergio-costas commented 1 year ago

@tigarmo Mmm... odd... in ubuntu there is this line in ~/.bashrc:

imagen

It forces the window title to the current folder every time the prompt appears... which makes sense, because not all programs restore the window title.

Fedora has a similar line:

imagen

Are you using a ubuntu-derived distro? Which value returns in your system echo $TERM? (in my case, it returns xterm-256color).

Because all this seems to point to the konsole bug that delays the title change.

sergio-costas commented 11 months ago

@tigarmo This should be ready for merging. As commented, the konsole bug seems to be a problem in konsole itseld, that doesn't refresh the UI unless there is a change in the terminal itself. Also, it seems to be not possible to read the current title in the terminal (at least in a standard way), since it is set using ANSI commands. And since as soon as a key is pressed, the title is updated in konsole, I think that it's not a true problem.

sergio-costas commented 11 months ago

Also, the linting bug seems to be a thing of setuptools_scm.