Skip to content
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
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: "Shard to create a REPL interface"
authors:
- I3oris <boris31.resch@gmail.com>

crystal: 1.5.0
crystal: 1.13.0

license: MIT

Expand Down
25 changes: 1 addition & 24 deletions src/char_reader.cr
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,9 @@ module Reply
@slice_buffer = Bytes.new(buffer_size)
end

def read_char(from io : T = STDIN) forall T
{% if flag?(:win32) && T <= IO::FileDescriptor %}
handle = LibC._get_osfhandle(io.fd)
raise RuntimeError.from_errno("_get_osfhandle") if handle == -1

raw(io) do
LibC.ReadConsoleA(LibC::HANDLE.new(handle), @slice_buffer, @slice_buffer.size, out nb_read, nil)

parse_escape_sequence(@slice_buffer[0...nb_read])
end
{% else %}
def read_char(from io : IO = STDIN)
nb_read = raw(io, &.read(@slice_buffer))
parse_escape_sequence(@slice_buffer[0...nb_read])
{% end %}
end

private def parse_escape_sequence(chars : Bytes) : Char | Sequence | String?
Expand Down Expand Up @@ -184,15 +173,3 @@ module Reply
end
end
end

{% if flag?(:win32) %}
lib LibC
STD_INPUT_HANDLE = -10

fun ReadConsoleA(hConsoleInput : Void*,
lpBuffer : Void*,
nNumberOfCharsToRead : UInt32,
lpNumberOfCharsRead : UInt32*,
pInputControl : Void*) : UInt8
end
{% end %}
3 changes: 0 additions & 3 deletions src/term_size.cr
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,7 @@ end
dwMaximumWindowSize : COORD
end

STD_OUTPUT_HANDLE = -11

fun GetConsoleScreenBufferInfo(hConsoleOutput : Void*, lpConsoleScreenBufferInfo : CONSOLE_SCREEN_BUFFER_INFO*) : Void
fun GetStdHandle(nStdHandle : UInt32) : Void*
end
{% else %}
lib LibC
Expand Down