Class: Termios::Termios

Inherits:
Object
  • Object
show all
Defined in:
ext/termios.c,
lib/termios.rb,
ext/termios.c

Overview

Encupsalates termios parameters.

See also: termios(3)

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#ccObject (readonly) Also known as: c_cc

control characters

#cflagObject (readonly) Also known as: c_cflag

control modes

#iflagObject (readonly) Also known as: c_iflag

input modes

#ispeedObject (readonly) Also known as: c_ispeed

input baud rate

#lflagObject (readonly) Also known as: c_lflag

local modes

#oflagObject (readonly) Also known as: c_oflag

output modes

#ospeedObject (readonly) Also known as: c_ospeed

output baud rate

Instance Method Details

#cc=(value) ⇒ Object (readonly) Also known as: c_cc=

Updates control characters of the object.



112
113
114
# File 'ext/termios.c', line 112

static VALUE
termios_set_cc(self, value)
VALUE self, value;

#cflag=(flag) ⇒ Object (readonly) Also known as: c_cflag=

Updates control modes of the object.



82
83
84
# File 'ext/termios.c', line 82

static VALUE
termios_set_cflag(self, value)
VALUE self, value;

#dupObject

Produces a shallow copy of the object.



635
636
637
# File 'ext/termios.c', line 635

static VALUE
termios_dup(self)
VALUE self;

#dupObject

Produces a shallow copy of the object.



635
636
637
# File 'ext/termios.c', line 635

static VALUE
termios_dup(self)
VALUE self;

#iflag=(flag) ⇒ Object (readonly) Also known as: c_iflag=

Updates input modes of the object.



52
53
54
# File 'ext/termios.c', line 52

static VALUE
termios_set_iflag(self, value)
VALUE self, value;

#inspectObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/termios.rb', line 46

def inspect
  str = "\#<#{self.class}"
  if self.ispeed == self.ospeed
    speed = (BAUDS[self.ispeed] || "B???").to_s[1..-1]
    str << " speed #{speed} baud;"
  else
    ispeed = (BAUDS[self.ispeed] || "B???").to_s[1..-1]
    ospeed = (BAUDS[self.ospeed] || "B???").to_s[1..-1]
    str << " ispeed #{ispeed} baud; ospeed #{ospeed} baud;"
  end

  CCINDEX_NAMES.each {|ccindex|
    next if ccindex == :VMIN || ccindex == :VTIME
    str << " #{ccindex.to_s[1..-1].downcase}"
    str << "=#{VISIBLE_CHAR[self.cc[::Termios.const_get(ccindex)]]}"
  }
  str << " min=#{self.cc[VMIN]}"
  str << " time=#{self.cc[VTIME]}"

  [
    [:cflag,
     CFLAG_NAMES-[:CBAUD, :CBAUDEX, :CIBAUD, :EXTA, :EXTB],
     CFLAG_CHOICES],
    [:iflag, IFLAG_NAMES, nil],
    [:oflag, OFLAG_NAMES, OFLAG_CHOICES],
    [:lflag, LFLAG_NAMES, nil]
  ].each {|l|
    str << ";"
    flag_type, flag_names, choices = l
    flags = self.send(flag_type)
    choice_names = choices ? choices.values.flatten : []
    (flag_names-choice_names).each {|name|
      str << " "
      if choices and ns = choices[name]
        mask = ::Termios.const_get(name)
        ns.each {|n|
          if (flags & mask) == ::Termios.const_get(n)
            str << n.to_s.downcase
            break
          end
        }
      else
        str << "-" if (flags & ::Termios.const_get(name)) == 0
        str << name.to_s.downcase
      end
    }
  }

  str << ">"
  str
end

#ispeed=(speed) ⇒ Object (readonly) Also known as: c_ispeed=

Updates input baud rate of the object.



128
129
130
# File 'ext/termios.c', line 128

static VALUE
termios_set_ispeed(self, value)
VALUE self, value;

#lflag=(flag) ⇒ Object (readonly) Also known as: c_lflag=

Updates local modes of the object.



97
98
99
# File 'ext/termios.c', line 97

static VALUE
termios_set_lflag(self, value)
VALUE self, value;

#oflag=(flag) ⇒ Object (readonly) Also known as: c_oflag=

Updates output modes of the object.



67
68
69
# File 'ext/termios.c', line 67

static VALUE
termios_set_oflag(self, value)
VALUE self, value;

#ospeed=(speed) ⇒ Object (readonly) Also known as: c_ospeed=

Updates output baud rate of the object.



143
144
145
# File 'ext/termios.c', line 143

static VALUE
termios_set_ospeed(self, value)
VALUE self, value;

#pretty_print(q) ⇒ Object

:nodoc:



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/termios.rb', line 98

def pretty_print(q)	# :nodoc:
  q.object_group(self) {
    if self.ispeed == self.ospeed
      speed = (BAUDS[self.ispeed] || "B???").to_s[1..-1]
      q.fill_breakable; q.text "speed #{speed} baud;"
    else
      ispeed = (BAUDS[self.ispeed] || "B???").to_s[1..-1]
      ospeed = (BAUDS[self.ospeed] || "B???").to_s[1..-1]
      q.fill_breakable; q.text "ispeed #{ispeed} baud;"
      q.fill_breakable; q.text "ospeed #{ospeed} baud;"
    end
    q.breakable

    q.seplist(CCINDEX_NAMES-[:VMIN, :VTIME],
              lambda { q.fill_breakable }) {|ccindex|
      q.text ccindex.to_s[1..-1].downcase
      q.text "=#{VISIBLE_CHAR[self.cc[::Termios.const_get(ccindex)]]}"
    }
    q.breakable; q.text "min=#{self.cc[VMIN]}"
    q.fill_breakable; q.text "time=#{self.cc[VTIME]}"

    [
      [:cflag,
       CFLAG_NAMES-[:CBAUD, :CBAUDEX, :CIBAUD, :EXTA, :EXTB],
       CFLAG_CHOICES],
      [:iflag, IFLAG_NAMES, nil],
      [:oflag, OFLAG_NAMES, OFLAG_CHOICES],
      [:lflag, LFLAG_NAMES, nil]
    ].each {|l|
      q.text ";"
      q.breakable
      flag_type, flag_names, choices = l
      flags = self.send(flag_type)
      choice_names = choices ? choices.values.flatten : []
      q.seplist(flag_names-choice_names,
                lambda { q.fill_breakable }) {|name|
        if choices and ns = choices[name]
          mask = ::Termios.const_get(name)
          ns.each {|n|
            if (flags & mask) == ::Termios.const_get(n)
              q.text n.to_s.downcase
              break
            end
          }
        else
          q.text "-" if (flags & ::Termios.const_get(name)) == 0
          q.text name.to_s.downcase
        end
      }
    }
  }
end