Module: STTY

Includes:
Termios
Defined in:
lib/stty.rb

Constant Summary

DEFAULT_CC =
[3, 28, 127, 21, 4, 0, 1, 0, 17, 19, 26, 0, 18, 15, 23, 22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

Instance Method Summary (collapse)

Instance Method Details

- (Object) cbreak(&blk)



283
284
285
# File 'lib/stty.rb', line 283

def cbreak(&blk)
  noicanon(&blk)
end

- (Object) cbreak=(bool)



279
280
281
# File 'lib/stty.rb', line 279

def cbreak=(bool)
  self.icanon = !bool
end

- (Boolean) cbreak?



275
276
277
# File 'lib/stty.rb', line 275

def cbreak?
  !self.icanon?
end

- (Object) cols(n) Also known as: columns



381
382
383
384
385
# File 'lib/stty.rb', line 381

def cols(n)
  data = [self.size[0], n, 0, 0].pack('SSSS')

  self.ioctl(TIOCSWINSZ, data) >= 0 ? true : false
end

- (Object) cooked(&blk)



362
363
364
# File 'lib/stty.rb', line 362

def cooked(&blk)
  noraw(&blk)
end

- (Object) cooked=(bool)



358
359
360
# File 'lib/stty.rb', line 358

def cooked=(bool)
  self.raw = !bool
end

- (Boolean) cooked?



352
353
354
355
356
# File 'lib/stty.rb', line 352

def cooked?
  %w{ignbrk brkint ignpar parmrk inpck istrip inlcr igncr icrnl ixon ixoff iuclc ixany imaxbel opost isig icanon xcase}.map {|sym|
    self.send("#{sym}?")
  }.inject(:&)
end

- (Object) crt



177
178
179
180
181
182
183
184
185
186
187
# File 'lib/stty.rb', line 177

def crt
  if block_given?
    return echoe { echoctl { echoke {
      yield self
    } } }
  else
    echoe; echoctl; echoke
  end

  nil
end

- (Object) crtkill



251
252
253
254
255
256
257
258
259
260
261
# File 'lib/stty.rb', line 251

def crtkill
  if block_given?
    return echoprt { echoe {
      yield self
    } }
  else
    echoprt; echoe
  end

  nil
end

- (Boolean) crtkill?



247
248
249
# File 'lib/stty.rb', line 247

def crtkill?
  echoprt? and echoe?
end

- (Object) dec



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/stty.rb', line 189

def dec
  if block_given?
    x = [self.intr, self.erase, self.kill]

    return echoe { echoctl { echoke { noixany {
      self.intr, self.erase, self.kill = 0x03, 0x7f, 0x16
      yield(self).tap {
        self.intr, self.erase, self.kill = x
      }
    } } } }
  else
    echoe; echoctl; echoke; noixany
    self.intr, self.erase, self.kill = 0x03, 0x7f, 0x16
  end

  nil
end

- (Object) ek



136
137
138
# File 'lib/stty.rb', line 136

def ek
  self.erase, self.kill = DEFAULT_CC[VERASE], DEFAULT_CC[VKILL]
end

- (Object) evenp



140
141
142
# File 'lib/stty.rb', line 140

def evenp
  self.parenb; self.noparodd; self.cs7
end

- (Object) ispeed=(bauds)



26
27
28
29
30
31
32
# File 'lib/stty.rb', line 26

def ispeed=(bauds)
  return unless bauds.is_a?(Integer)
  t = self.tcgetattr
  t.ispeed = bauds
  self.tcsetattr(TCSANOW, t)
  self
end

- (Object) lcase



148
149
150
151
152
153
154
155
156
157
158
# File 'lib/stty.rb', line 148

def lcase
  if block_given?
    return xcase { iuclc { olcuc {
      yield self
    } } }
  else
    self.xcase; self.iuclc; self.olcuc
  end

  nil
end

- (Object) nl



223
224
225
226
227
228
229
230
231
232
233
# File 'lib/stty.rb', line 223

def nl
  if block_given?
    return noicrnl { noonlcr {
      yield self
    } }
  else
    noicrnl; noonlcr
  end

  nil
end

- (Object) nocbreak(&blk)



287
288
289
# File 'lib/stty.rb', line 287

def nocbreak(&blk)
  icanon(&blk)
end

- (Object) nocooked(&blk)



366
367
368
# File 'lib/stty.rb', line 366

def nocooked(&blk)
  raw(&blk)
end

- (Object) nocrtkill



263
264
265
266
267
268
269
270
271
272
273
# File 'lib/stty.rb', line 263

def nocrtkill
  if block_given?
    return echoctl { echok {
      yield self
    } }
  else
    echoctl; echok
  end

  nil
end

- (Object) noevenp



144
145
146
# File 'lib/stty.rb', line 144

def noevenp
  self.noparenb; self.cs8
end

- (Object) nolcase



160
161
162
163
164
165
166
167
168
169
170
# File 'lib/stty.rb', line 160

def nolcase
  if block_given?
    return noxcase { noiuclc { noolcuc {
      yield self
    } } }
  else
    self.noxcase; self.noiuclc; self.noolcuc
  end

  nil
end

- (Object) nolitout



172
173
174
175
# File 'lib/stty.rb', line 172

def nolitout
  self.parenb; self.istrip; self.opost; self.cs7
  nil
end

- (Object) nonl



235
236
237
238
239
240
241
242
243
244
245
# File 'lib/stty.rb', line 235

def nonl
  if block_given?
    return icrnl { noinlcr { noigncr { onlcr { noocrnl { noonlret {
      yield self
    } } } } } }
  else
    icrnl; noinlcr; noigncr; onlcr; noocrnl; noonlret
  end

  nil
end

- (Object) nooddp



211
212
213
# File 'lib/stty.rb', line 211

def nooddp
  self.noparenb; self.cs8
end

- (Object) nopass8



219
220
221
# File 'lib/stty.rb', line 219

def nopass8
  self.noparenb; self.noistrip; self.cs7
end

- (Object) noraw(&blk)



338
339
340
341
342
343
344
345
346
347
348
349
350
# File 'lib/stty.rb', line 338

def noraw(&blk)
  if blk
    %w{ignbrk brkint ignpar parmrk inpck istrip inlcr igncr icrnl ixon ixoff iuclc ixany imaxbel opost isig icanon xcase}.inject {|block, sym|
      lambda {
        self.send(sym, &block)
      }
    }.call
  else
    %w{ignbrk brkint ignpar parmrk inpck istrip inlcr igncr icrnl ixon ixoff iuclc ixany imaxbel opost isig icanon xcase}.each {|sym|
      self.send(sym)
    }
  end
end

- (Object) notabs



132
133
134
# File 'lib/stty.rb', line 132

def notabs
  self.tab3
end

- (Object) oddp



207
208
209
# File 'lib/stty.rb', line 207

def oddp
  self.parenb; self.parodd; self.cs7
end

- (Object) ospeed=(bauds)



34
35
36
37
38
39
40
# File 'lib/stty.rb', line 34

def ospeed=(bauds)
  return unless bauds.is_a?(Integer)
  t = self.tcgetattr
  t.ospeed = bauds
  self.tcsetattr(TCSANOW, t)
  self
end

- (Object) pass8



215
216
217
# File 'lib/stty.rb', line 215

def pass8
  self.noparenb; self.noistrip; self.cs8
end

- (Object) raw(&blk)



324
325
326
327
328
329
330
331
332
333
334
335
336
# File 'lib/stty.rb', line 324

def raw(&blk)
  if blk
    %w{ignbrk brkint ignpar parmrk inpck istrip inlcr igncr icrnl ixon ixoff iuclc ixany imaxbel opost isig icanon xcase}.inject(blk) {|block, sym|
      lambda {|*|
        self.send("no#{sym}", &block)
      }
    }.call
  else
    %w{ignbrk brkint ignpar parmrk inpck istrip inlcr igncr icrnl ixon ixoff iuclc ixany imaxbel opost isig icanon xcase}.each {|sym|
      self.send("no#{sym}")
    }
  end
end

- (Object) raw=(bool)



311
312
313
314
315
316
317
318
319
320
321
322
# File 'lib/stty.rb', line 311

def raw=(bool)
  %w{ignbrk brkint ignpar parmrk inpck istrip inlcr igncr icrnl ixon ixoff iuclc ixany imaxbel opost isig icanon xcase}.each {|sym|
    self.send("#{sym}=", !bool)
  }

  if bool
    self.min = 1
    self.time = 0
  end

  self
end

- (Boolean) raw?



305
306
307
308
309
# File 'lib/stty.rb', line 305

def raw?
  %w{ignbrk brkint ignpar parmrk inpck istrip inlcr igncr icrnl ixon ixoff iuclc ixany imaxbel opost isig icanon xcase}.map {|sym|
    !self.send("#{sym}?")
  }.inject(:&) and self.min == 1 and self.time == 0
end

- (Object) rows(n)



388
389
390
391
392
# File 'lib/stty.rb', line 388

def rows(n)
  data = [n, self.size[1], 0, 0].pack('SSSS')

  self.ioctl(TIOCSWINSZ, data) >= 0 ? true : false
end

- (Object) sane



291
292
293
294
295
296
297
298
299
300
301
302
303
# File 'lib/stty.rb', line 291

def sane
  self.cread; self.noignbrk; self.brkint; self.noinlcr; self.igncr; self.icrnl
  self.noiutf8; self.noixoff; self.noiuclc; self.noixany; self.imaxbel; self.opost
  self.noolcuc; self.noocrnl; self.onlcr; self.noonocr; self.noonlret; self.noofill
  self.noofdel; self.nl0; self.cr0; self.tab0; self.bs0; self.vt0; self.ff0
  self.isig; self.icanon; self.iexten; self.echo; self.echoe; self.echok
  self.noechonl; self.nonoflsh; self.noxcase; self.notostop; self.noechoprt
  self.echoctl; self.echoke
  t = self.tcgetattr
  t.cc = DEFAULT_CC[0, NCCS]
  self.tcsetattr(TCSANOW, t)
  nil
end

- (Object) size



370
371
372
373
374
375
376
377
378
379
# File 'lib/stty.rb', line 370

def size
  data = [0, 0, 0, 0].pack('SSSS')

  if self.ioctl(TIOCGWINSZ, data) >= 0
    rows, cols, * = data.unpack('SSSS')
    [rows, cols]
  else
    [80, 80]
  end
end

- (Object) speed=(bauds)



42
43
44
45
# File 'lib/stty.rb', line 42

def speed=(bauds)
  self.ispeed = bauds
  self.ospeed = bauds
end

- (Object) tabs



128
129
130
# File 'lib/stty.rb', line 128

def tabs
  self.tab0
end