subscribe
Tags:
 
2012
2011
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008
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
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         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,nulltruetrue,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>&& 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);         new Term();         t.run();     } }
Comments
Name:
not required
Email:
not required (will not be displayed)
Website:
not required (will link your name to your site)
Comment:
required
Please do not post HTML code or bbcode unless you want it to show up as code in your post. (or if you are a blog spammer, in which case, you probably aren't reading this anyway).
Prove you are human by solving a math problem! I'm sorry, but due to an increase of blog spam, I've had to implement a CAPTCHA.
Problem:
2 plus 6
Answer:
required