This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Make ^C action in Konsole context dependent

1

Votes
1
0
Tags: None
(comma "," separated)
rparkins
Registered Member
Posts
2
Karma
0
^C has been used as an interrupt character for command shells since before the original Bell Labs Unix™: for many users it is almost a reflex to type ^C to interrupt a program being run from a (real or virtual) terminal. ^C has been used as a command to copy the selection in GUI's since at least the original Macintosh™ (it had no Control key and used ⌘C, and the Xerox Alto, which preceded the Macintosh, had the function, but I don't know what key invoked it). For many users it is almost a reflex to drag the mouse over some text and type ^C to copy it. Konsole is a GUI which runs a command shell, so these two uses of ^C clash, and I have to use the Keyboard Shortcuts settings page to choose one of them, which means my reflexes are doing the wrong thing much of the time.

However the contexts in which these two action are appropriate are different. If there is nothing selected, the copy action is invalid and grayed out in the menu. If the shell is at a command prompt, interrupting it will just cause it to reissue the prompt, which isn't very useful. Konsole can certainly tell whether or not the selection is empty by reading it, and it seems to be able to tell whether its shell is running a command since it puts the command name into the window title bar. So it should be possible for Konsole to tell which action is appropriate. It isn't clear which action to take if some text is selected and the shell is running a command, but this situation is rare since it is hard to select some text while the command's output is scrolling up the screen. At any rate it is much less troublesome if ^C doesn't do what I want in this case.

I would like to suggest an option to make the choice of action to take when ^C is typed dependent on context. A case could be made for more generality in having a different set of key bindings for all keys for each context: ^Z (undo versus SIGTSTP) is another candidate, although currently Konsole doesn't support undoing a paste.

I did look at trying to do this myself and making a pull request, but it doesn't seem to be possible to build an install a custom version of Konsole without building the entire KDE environment, which is a large exercise involving downloading a lot of tools and would leave me with a KDE version different from the one that my Linux distro supports, so I wouldn't be able to install updates.
rparkins
Registered Member
Posts
2
Karma
0
Well, actually if I go to Settings->Configure Keyboard Shortcuts and set the copy shortcut to Ctrl+C, rather than the default of Ctrl+Shift+C, it does indeed do a Copy if the selection is nonempty and send a SIGINT if the selection is empty. This doesn't seem to be documented, and I thought I had tried it before. Of course I would like to be able to program another key to send a SIGINT if I'm running a program which gets into a loop or sends lots of output and I happened to have a nonempty selection when I started it, and I can do that by setting the key bindings for the current profile to make something else send a \x03 (the raw code for Ctrl+C), which doesn't seem to be reinterpreted by the shortcut configurator. I can also send a SIGINT from the Edit menu, and that is documented, or just click in Konsole's window, which cancels the selection (this also doesn't seem to be explicitly documented although it's fairly standard for text selections) and I can then type Ctrl+C to send a SIGINT.
Lachu
Registered Member
Posts
864
Karma
1
OS
Great idea!

I will suggest similar solution: when CTRL+C was pressed, copy text to clipboard and shown message telling if user click CTRL+C again, SIGTERM will be send. If user select another text or empty text, we could free CTRL+C pressed flag of Konsole's tab window, so if user again click ctrl+c, we copy text and again allow to press ctrl+c to term process. Of course, when there is not any text select, ctrl+c always will send sigterm.


Lachu, proud to be a member of KDE forums since 2008-Nov.


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Google [Bot], Yahoo [Bot]