| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
package term |
| 7 |
|
| 8 |
const ( |
| 9 |
|
| 10 |
sshIflag = iota |
| 11 |
sshOflag |
| 12 |
sshCflag |
| 13 |
sshLflag |
| 14 |
sshCchar |
| 15 |
sshTspeed |
| 16 |
sshNOP |
| 17 |
|
| 18 |
|
| 19 |
sshTTYOPEND = 0 |
| 20 |
sshVINTR = 1 |
| 21 |
sshVQUIT = 2 |
| 22 |
sshVERASE = 3 |
| 23 |
sshVKILL = 4 |
| 24 |
sshVEOF = 5 |
| 25 |
sshVEOL = 6 |
| 26 |
sshVEOL2 = 7 |
| 27 |
sshVSTART = 8 |
| 28 |
sshVSTOP = 9 |
| 29 |
sshVSUSP = 10 |
| 30 |
sshVDSUSP = 11 |
| 31 |
sshVREPRINT = 12 |
| 32 |
sshVWERASE = 13 |
| 33 |
sshVLNEXT = 14 |
| 34 |
sshVFLUSH = 15 |
| 35 |
sshVSWTCH = 16 |
| 36 |
sshVSTATUS = 17 |
| 37 |
sshVDISCARD = 18 |
| 38 |
sshIGNPAR = 30 |
| 39 |
sshPARMRK = 31 |
| 40 |
sshINPCK = 32 |
| 41 |
sshISTRIP = 33 |
| 42 |
sshINLCR = 34 |
| 43 |
sshIGNCR = 35 |
| 44 |
sshICRNL = 36 |
| 45 |
sshIUCLC = 37 |
| 46 |
sshIXON = 38 |
| 47 |
sshIXANY = 39 |
| 48 |
sshIXOFF = 40 |
| 49 |
sshIMAXBEL = 41 |
| 50 |
sshISIG = 50 |
| 51 |
sshICANON = 51 |
| 52 |
sshXCASE = 52 |
| 53 |
sshECHO = 53 |
| 54 |
sshECHOE = 54 |
| 55 |
sshECHOK = 55 |
| 56 |
sshECHONL = 56 |
| 57 |
sshNOFLSH = 57 |
| 58 |
sshTOSTOP = 58 |
| 59 |
sshIEXTEN = 59 |
| 60 |
sshECHOCTL = 60 |
| 61 |
sshECHOKE = 61 |
| 62 |
sshPENDIN = 62 |
| 63 |
sshOPOST = 70 |
| 64 |
sshOLCUC = 71 |
| 65 |
sshONLCR = 72 |
| 66 |
sshOCRNL = 73 |
| 67 |
sshONOCR = 74 |
| 68 |
sshONLRET = 75 |
| 69 |
sshCS7 = 90 |
| 70 |
sshCS8 = 91 |
| 71 |
sshPARENB = 92 |
| 72 |
sshPARODD = 93 |
| 73 |
sshTTYOPISPEED = 128 |
| 74 |
sshTTYOPOSPEED = 129 |
| 75 |
) |
| 76 |
|
| 77 |
var convertSSH = map[uint8]struct { |
| 78 |
tType uint |
| 79 |
native uint32 |
| 80 |
}{ |
| 81 |
sshTTYOPEND: {tType: sshNOP}, |
| 82 |
sshVINTR: {tType: sshCchar, native: VINTR}, |
| 83 |
sshVQUIT: {tType: sshCchar, native: VQUIT}, |
| 84 |
sshVERASE: {tType: sshCchar, native: VERASE}, |
| 85 |
sshVKILL: {tType: sshCchar, native: VKILL}, |
| 86 |
sshVEOF: {tType: sshCchar, native: VEOF}, |
| 87 |
sshVEOL: {tType: sshCchar, native: VEOL}, |
| 88 |
sshVEOL2: {tType: sshCchar, native: VEOL2}, |
| 89 |
sshVSTART: {tType: sshCchar, native: VSTART}, |
| 90 |
sshVSTOP: {tType: sshCchar, native: VSTOP}, |
| 91 |
sshVSUSP: {tType: sshCchar, native: VSUSP}, |
| 92 |
sshVDSUSP: {tType: sshCchar, native: sshNOP}, |
| 93 |
sshVREPRINT: {tType: sshCchar, native: VREPRINT}, |
| 94 |
sshVWERASE: {tType: sshCchar, native: VWERASE}, |
| 95 |
sshVLNEXT: {tType: sshCchar, native: VLNEXT}, |
| 96 |
sshVFLUSH: {tType: sshNOP}, |
| 97 |
sshVSWTCH: {tType: sshCchar, native: VSWTC}, |
| 98 |
sshVSTATUS: {tType: sshNOP}, |
| 99 |
sshVDISCARD: {tType: sshCchar, native: VDISCARD}, |
| 100 |
sshIGNPAR: {tType: sshIflag, native: IGNPAR}, |
| 101 |
sshPARMRK: {tType: sshIflag, native: PARMRK}, |
| 102 |
sshINPCK: {tType: sshIflag, native: INPCK}, |
| 103 |
sshISTRIP: {tType: sshIflag, native: ISTRIP}, |
| 104 |
sshINLCR: {tType: sshIflag, native: INLCR}, |
| 105 |
sshIGNCR: {tType: sshIflag, native: IGNCR}, |
| 106 |
sshICRNL: {tType: sshIflag, native: ICRNL}, |
| 107 |
sshIUCLC: {tType: sshIflag, native: IUCLC}, |
| 108 |
sshIXON: {tType: sshIflag, native: IXON}, |
| 109 |
sshIXANY: {tType: sshIflag, native: IXANY}, |
| 110 |
sshIXOFF: {tType: sshIflag, native: IXOFF}, |
| 111 |
sshIMAXBEL: {tType: sshIflag, native: IMAXBEL}, |
| 112 |
sshISIG: {tType: sshLflag, native: ISIG}, |
| 113 |
sshICANON: {tType: sshLflag, native: ICANON}, |
| 114 |
sshXCASE: {tType: sshLflag, native: XCASE}, |
| 115 |
sshECHO: {tType: sshLflag, native: ECHO}, |
| 116 |
sshECHOE: {tType: sshLflag, native: ECHOE}, |
| 117 |
sshECHOK: {tType: sshLflag, native: ECHOK}, |
| 118 |
sshECHONL: {tType: sshLflag, native: ECHONL}, |
| 119 |
sshNOFLSH: {tType: sshLflag, native: NOFLSH}, |
| 120 |
sshTOSTOP: {tType: sshLflag, native: TOSTOP}, |
| 121 |
sshIEXTEN: {tType: sshLflag, native: IEXTEN}, |
| 122 |
sshECHOCTL: {tType: sshLflag, native: ECHOCTL}, |
| 123 |
sshECHOKE: {tType: sshLflag, native: ECHOKE}, |
| 124 |
sshPENDIN: {tType: sshNOP}, |
| 125 |
sshOPOST: {tType: sshOflag, native: OPOST}, |
| 126 |
sshOLCUC: {tType: sshOflag, native: OLCUC}, |
| 127 |
sshONLCR: {tType: sshOflag, native: ONLCR}, |
| 128 |
sshOCRNL: {tType: sshOflag, native: OCRNL}, |
| 129 |
sshONOCR: {tType: sshOflag, native: ONOCR}, |
| 130 |
sshONLRET: {tType: sshOflag, native: ONLRET}, |
| 131 |
sshCS7: {tType: sshCflag, native: CS7}, |
| 132 |
sshCS8: {tType: sshCflag, native: CS8}, |
| 133 |
sshPARENB: {tType: sshCflag, native: PARENB}, |
| 134 |
sshPARODD: {tType: sshCflag, native: PARODD}, |
| 135 |
sshTTYOPISPEED: {tType: sshTspeed}, |
| 136 |
sshTTYOPOSPEED: {tType: sshTspeed}, |
| 137 |
} |
| 138 |
|
| 139 |
|
| 140 |
func (t *Termios) ToSSH() map[uint8]uint32 { |
| 141 |
sshModes := make(map[uint8]uint32, len(convertSSH)) |
| 142 |
var flags uint32 |
| 143 |
for sshID, tios := range convertSSH { |
| 144 |
switch tios.tType { |
| 145 |
case sshIflag: |
| 146 |
flags = t.Iflag |
| 147 |
case sshOflag: |
| 148 |
flags = t.Oflag |
| 149 |
case sshLflag: |
| 150 |
flags = t.Lflag |
| 151 |
case sshCflag: |
| 152 |
flags = t.Cflag |
| 153 |
case sshCchar: |
| 154 |
sshModes[sshID] = uint32(t.Cc[tios.native]) |
| 155 |
continue |
| 156 |
case sshTspeed: |
| 157 |
sshModes[sshTTYOPISPEED], sshModes[sshTTYOPOSPEED] = t.Ispeed, t.Ospeed |
| 158 |
continue |
| 159 |
default: |
| 160 |
continue |
| 161 |
} |
| 162 |
var onOff uint32 |
| 163 |
if tios.native&flags > 0 { |
| 164 |
onOff = 1 |
| 165 |
} |
| 166 |
sshModes[sshID] = onOff |
| 167 |
} |
| 168 |
return sshModes |
| 169 |
} |
| 170 |
|
| 171 |
|
| 172 |
func (t *Termios) FromSSH(termModes map[uint8]uint32) { |
| 173 |
var flags *uint32 |
| 174 |
for sshID, val := range termModes { |
| 175 |
switch convertSSH[sshID].tType { |
| 176 |
case sshIflag: |
| 177 |
flags = &t.Iflag |
| 178 |
case sshOflag: |
| 179 |
flags = &t.Oflag |
| 180 |
case sshLflag: |
| 181 |
flags = &t.Lflag |
| 182 |
case sshCflag: |
| 183 |
flags = &t.Cflag |
| 184 |
case sshCchar: |
| 185 |
t.Cc[convertSSH[sshID].native] = byte(val) |
| 186 |
continue |
| 187 |
case sshTspeed: |
| 188 |
if sshID == sshTTYOPISPEED { |
| 189 |
t.Ispeed = val |
| 190 |
} else { |
| 191 |
t.Ospeed = val |
| 192 |
} |
| 193 |
continue |
| 194 |
default: |
| 195 |
continue |
| 196 |
} |
| 197 |
if val > 0 { |
| 198 |
*flags |= convertSSH[sshID].native |
| 199 |
} else { |
| 200 |
*flags &^= convertSSH[sshID].native |
| 201 |
} |
| 202 |
} |
| 203 |
} |