1 //
2 // Copyright (c) 2010-2018 Antmicro
3 //
4 // This file is licensed under the MIT License.
5 // Full license text is available in 'licenses/MIT.txt'.
6 //
7 #if PLATFORM_LINUX
8 using System.Diagnostics;
9 
10 namespace Antmicro.Renode.UI
11 {
12     [ConsoleBackendAnalyzerProvider("XTerm")]
13     public class XTermProvider : ProcessBasedProvider
14     {
CreateProcess(string consoleName, string command)15         protected override Process CreateProcess(string consoleName, string command)
16         {
17             var p = new Process();
18             var position = WindowPositionProvider.Instance.GetNextPosition();
19             var minFaceSize = @"XTerm.*.faceSize1: 6";
20             var keys = @"XTerm.VT100.translations: #override \\n" +
21                         // disable menu on CTRL click
22                         @"!Ctrl <Btn1Down>: ignore()\\n" +
23                         @"!Ctrl <Btn2Down>: ignore()\\n" +
24                         @"!Ctrl <Btn3Down>: ignore()\\n" +
25                         @"!Lock Ctrl <Btn1Down>: ignore()\\n" +
26                         @"!Lock Ctrl <Btn2Down>: ignore()\\n" +
27                         @"!Lock Ctrl <Btn3Down>: ignore()\\n" +
28                         @"!@Num_Lock Ctrl <Btn1Down>: ignore()\\n" +
29                         @"!@Num_Lock Ctrl <Btn2Down>: ignore()\\n" +
30                         @"!@Num_Lock Ctrl <Btn3Down>: ignore()\\n" +
31                         @"!Lock Ctrl @Num_Lock <Btn1Down>: ignore()\\n" +
32                         @"!Lock Ctrl @Num_Lock <Btn2Down>: ignore()\\n" +
33                         @"!Lock Ctrl @Num_Lock <Btn3Down>: ignore()\\n" +
34                         // change default font size change keys into CTRL +/-
35                         @"Shift~Ctrl <KeyPress> KP_Add:ignore()\\n" +
36                         @"Shift Ctrl <KeyPress> KP_Add:ignore()\\n" +
37                         @"Shift <KeyPress> KP_Subtract:ignore()\\n" +
38                         @"Ctrl <KeyPress> KP_Subtract:smaller-vt-font()\\n" +
39                         @"Ctrl <KeyPress> KP_Add:larger-vt-font() \\n";
40             var scrollKeys = @"XTerm.VT100.scrollbar.translations: #override \\n"+
41                                 @"<Btn5Down>: StartScroll(Forward) \\n"+
42                                 @"<Btn1Down>: StartScroll(Continuous) MoveThumb() NotifyThumb() \\n"+
43                                 @"<Btn4Down>: StartScroll(Backward) \\n"+
44                                 @"<Btn3Down>: StartScroll(Continuous) MoveThumb() NotifyThumb() \\n"+
45                                 @"<Btn2Down>: ignore() \\n"+
46                                 @"<Btn1Motion>: MoveThumb() NotifyThumb() \\n"+
47                                 @"<BtnUp>: NotifyScroll(Proportional) EndScroll()";
48             var fonts = "DejaVu Sans Mono, Ubuntu Sans Mono, Droid Sans Mono";
49 
50             var xtermCommand = string.Format(@"-T '{0}' -sb -rightbar -xrm '*Scrollbar.thickness: 10' -xrm '*Scrollbar.background: #CCCCCC' -geometry +{1}+{2}  -xrm '*Scrollbar.foreground: #444444' -xrm 'XTerm.vt100.background: black' -xrm 'XTerm.vt100.foreground: white' -fa '{3}' -fs 10 -xrm '{4}' -xrm '{5}' -xrm '{6}' -e {7}",
51                 consoleName, (int)position.X, (int)position.Y, fonts, keys, minFaceSize, scrollKeys, command);
52 
53             p.StartInfo = new ProcessStartInfo("xterm", xtermCommand)
54             {
55                 UseShellExecute = false,
56                 RedirectStandardError = true,
57                 RedirectStandardOutput = true,
58                 RedirectStandardInput = true,
59             };
60             p.EnableRaisingEvents = true;
61             p.Exited += (sender, e) =>
62             {
63                 var proc = sender as Process;
64                 if(proc.ExitCode != 0 && proc.ExitCode != 15)
65                 {
66                     LogError("Xterm", xtermCommand, proc.ExitCode);
67                 }
68                 InnerOnClose();
69             };
70             return p;
71         }
72     }
73 }
74 #endif
75