Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate Termios #12940

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 8 additions & 11 deletions src/crystal/system/unix/file_descriptor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,9 @@ module Crystal::System::FileDescriptor

private def system_echo(enable : Bool, & : ->)
system_console_mode do |mode|
if enable
mode.c_lflag |= Termios::LocalMode.flags(ECHO, ECHOE, ECHOK, ECHONL).value
else
mode.c_lflag &= ~(Termios::LocalMode.flags(ECHO, ECHOE, ECHOK, ECHONL).value)
end
if LibC.tcsetattr(fd, Termios::LineControl::TCSANOW, pointerof(mode)) != 0
flags = LibC::ECHO | LibC::ECHOE | LibC::ECHOK | LibC::ECHONL
mode.c_lflag = enable ? (mode.c_lflag | flags) : (mode.c_lflag & ~flags)
if LibC.tcsetattr(fd, LibC::TCSANOW, pointerof(mode)) != 0
raise IO::Error.from_errno("tcsetattr")
end
yield
Expand All @@ -209,11 +206,11 @@ module Crystal::System::FileDescriptor
if enable
LibC.cfmakeraw(pointerof(mode))
else
mode.c_iflag |= Termios::InputMode.flags(BRKINT, ISTRIP, ICRNL, IXON).value
mode.c_oflag |= Termios::OutputMode::OPOST.value
mode.c_lflag |= Termios::LocalMode.flags(ECHO, ECHOE, ECHOK, ECHONL, ICANON, ISIG, IEXTEN).value
mode.c_iflag |= LibC::BRKINT | LibC::ISTRIP | LibC::ICRNL | LibC::IXON
mode.c_oflag |= LibC::OPOST
mode.c_lflag |= LibC::ECHO | LibC::ECHOE | LibC::ECHOK | LibC::ECHONL | LibC::ICANON | LibC::ISIG | LibC::IEXTEN
end
if LibC.tcsetattr(fd, Termios::LineControl::TCSANOW, pointerof(mode)) != 0
if LibC.tcsetattr(fd, LibC::TCSANOW, pointerof(mode)) != 0
raise IO::Error.from_errno("tcsetattr")
end
yield
Expand All @@ -228,7 +225,7 @@ module Crystal::System::FileDescriptor

before = mode
ret = yield mode
LibC.tcsetattr(fd, Termios::LineControl::TCSANOW, pointerof(before))
LibC.tcsetattr(fd, LibC::TCSANOW, pointerof(before))
ret
end
end
11 changes: 11 additions & 0 deletions src/termios.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require "c/termios"

@[Deprecated]
module Termios
@[Deprecated]
@[Flags]
enum InputMode
BRKINT = LibC::BRKINT
Expand All @@ -18,6 +20,7 @@ module Termios
end

{% if flag?(:freebsd) %}
@[Deprecated]
@[Flags]
enum OutputMode
OPOST = LibC::OPOST
Expand All @@ -31,6 +34,7 @@ module Termios
end
{% elsif flag?(:dragonfly) %}
# FIXME: Verify
@[Deprecated]
@[Flags]
enum OutputMode
OPOST = LibC::OPOST
Expand All @@ -43,6 +47,7 @@ module Termios
TAB3 = LibC::TAB3
end
{% elsif flag?(:netbsd) || flag?(:openbsd) %}
@[Deprecated]
@[Flags]
enum OutputMode
OPOST = LibC::OPOST
Expand All @@ -52,6 +57,7 @@ module Termios
ONLRET = LibC::ONLRET
end
{% else %}
@[Deprecated]
@[Flags]
enum OutputMode
OPOST = LibC::OPOST
Expand Down Expand Up @@ -86,6 +92,7 @@ module Termios
end
{% end %}

@[Deprecated]
enum BaudRate
B0 = LibC::B0
B50 = LibC::B50
Expand All @@ -105,6 +112,7 @@ module Termios
B38400 = LibC::B38400
end

@[Deprecated]
enum ControlMode
CSIZE = LibC::CSIZE
CS5 = LibC::CS5
Expand All @@ -119,6 +127,7 @@ module Termios
CLOCAL = LibC::CLOCAL
end

@[Deprecated]
@[Flags]
enum LocalMode : Int64
ECHO = LibC::ECHO
Expand All @@ -132,13 +141,15 @@ module Termios
TOSTOP = LibC::TOSTOP
end

@[Deprecated]
@[Flags]
enum AttributeSelection
TCSANOW = LibC::TCSANOW
TCSADRAIN = LibC::TCSADRAIN
TCSAFLUSH = LibC::TCSAFLUSH
end

@[Deprecated]
enum LineControl
TCSANOW = LibC::TCSANOW
TCSADRAIN = LibC::TCSADRAIN
Expand Down