2009-06-01
Having recently created a custom terminal app to fit my usage needs, I quickly became aware of two issues with the terminal application that really bothered me.
1. when running screen, backspace didn't work. Since I typically have a screen session running when I'm using a terminal, this was a high priority problem. Fortunately, a bit of research in the VTE documentation turned up the class function "set_backspace_binding", which sets what type of input is sent when a user presses the backspace key. I opted for sending an ASCII Backspace character.
2. Being able to copy and paste from a terminal window is a feature that I have become accustomed to, yet muterm was definitely lacking. Easy enough, check key-presses and if the user has pressed "control+shift+c", copy the selected text in the terminal to the clipboard. Do I really need to mention what "control+shift+v" does? OK, it pastes text from the clipboard to the terminal.
Here is the new code with the fixes
1. when running screen, backspace didn't work. Since I typically have a screen session running when I'm using a terminal, this was a high priority problem. Fortunately, a bit of research in the VTE documentation turned up the class function "set_backspace_binding", which sets what type of input is sent when a user presses the backspace key. I opted for sending an ASCII Backspace character.
2. Being able to copy and paste from a terminal window is a feature that I have become accustomed to, yet muterm was definitely lacking. Easy enough, check key-presses and if the user has pressed "control+shift+c", copy the selected text in the terminal to the clipboard. Do I really need to mention what "control+shift+v" does? OK, it pastes text from the clipboard to the terminal.
Here is the new code with the fixes
using Gtk; using Vte; private class Term { private Terminal term; private Term() { //start with a gtk window Window w; //we also need a vte terminal //create our new window w = new Window(Gtk.WindowType.TOPLEVEL); //create the new terminal term = new Terminal(); //connect exiting on the terminal with quiting the app term.child_exited.connect ( (t)=> { Gtk.main_quit(); } ); //connect keypress events from the window term.key_press_event.connect((w,event) => {this.process_event(event); } ); //fork a command to run when the terminal is started term.fork_command(null,null,null,null, true, true,true); //set the default terminal backspace binding term.set_backspace_binding(TerminalEraseBinding.ASCII_BACKSPACE); //add the terminal to the window w.add(term); //maximize the window w.maximize(); //undecorate the window w.set_decorated(false); //try to set the icon try{ w.set_icon_from_file("/usr/share/pixmaps/gnome-term.png"); }catch(Error er) { //we don't really need to print this error stdout.printf(er.message); } //show our window and all children of our window w.show_all(); } private bool process_event(Gdk.EventKey event) { uint keyval; uint state; //we are looking for control+shift+c and control+shift+c keyval = event.keyval; state = event.state; //print some data if(keyval>0 && state>0) if(state==5) { if(keyval==67) { //this is a copy request term.copy_clipboard(); return true; }else if(keyval==86) { //this is a paste request term.paste_clipboard(); return true; } } return false; } private void run() { //start the gtk mainloop Gtk.main(); } private static void main(string[] args) { Term t; Gtk.init(ref args); t = new Term(); t.run(); } }
Comments