• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

JuliaLang / julia / #37527

pending completion
#37527

push

local

web-flow
make `IRShow.method_name` inferrable (#49607)

18 of 18 new or added lines in 3 files covered. (100.0%)

68710 of 81829 relevant lines covered (83.97%)

33068903.12 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

7.81
/stdlib/REPL/src/Terminals.jl
1
# This file is a part of Julia. License is MIT: https://julialang.org/license
2

3
module Terminals
4

5
export
6
    AbstractTerminal,
7
    TextTerminal,
8
    UnixTerminal,
9
    TerminalBuffer,
10
    TTYTerminal,
11
    cmove,
12
    cmove_col,
13
    cmove_down,
14
    cmove_left,
15
    cmove_line_down,
16
    cmove_line_up,
17
    cmove_right,
18
    cmove_up,
19
    disable_bracketed_paste,
20
    enable_bracketed_paste,
21
    end_keypad_transmit_mode,
22
    getX,
23
    getY,
24
    hascolor,
25
    pos,
26
    raw!
27

28
import Base:
29
    check_open, # stream.jl
30
    displaysize,
31
    flush,
32
    pipe_reader,
33
    pipe_writer,
34
    read,
35
    readuntil
36

37
## AbstractTerminal: abstract supertype of all terminals ##
38

39
abstract type AbstractTerminal <: Base.AbstractPipe end
40

41
## TextTerminal ##
42

43
abstract type TextTerminal <: AbstractTerminal end
44

45
# Terminal interface:
46
pipe_reader(::TextTerminal) = error("Unimplemented")
×
47
pipe_writer(::TextTerminal) = error("Unimplemented")
×
48
displaysize(::TextTerminal) = error("Unimplemented")
×
49
cmove(t::TextTerminal, x, y) = error("Unimplemented")
×
50
getX(t::TextTerminal) = error("Unimplemented")
×
51
getY(t::TextTerminal) = error("Unimplemented")
×
52
pos(t::TextTerminal) = (getX(t), getY(t))
×
53

54
# Relative moves (Absolute position fallbacks)
55
cmove_up(t::TextTerminal, n) = cmove(getX(t), max(1, getY(t)-n))
×
56
cmove_up(t) = cmove_up(t, 1)
×
57

58
cmove_down(t::TextTerminal, n) = cmove(getX(t), max(height(t), getY(t)+n))
×
59
cmove_down(t) = cmove_down(t, 1)
×
60

61
cmove_left(t::TextTerminal, n) = cmove(max(1, getX(t)-n), getY(t))
×
62
cmove_left(t) = cmove_left(t, 1)
×
63

64
cmove_right(t::TextTerminal, n) = cmove(max(width(t), getX(t)+n), getY(t))
×
65
cmove_right(t) = cmove_right(t, 1)
×
66

67
cmove_line_up(t::TextTerminal, n) = cmove(1, max(1, getY(t)-n))
×
68
cmove_line_up(t) = cmove_line_up(t, 1)
×
69

70
cmove_line_down(t::TextTerminal, n) = cmove(1, max(height(t), getY(t)+n))
×
71
cmove_line_down(t) = cmove_line_down(t, 1)
×
72

73
cmove_col(t::TextTerminal, c) = cmove(c, getY(t))
×
74

75
# Defaults
76
hascolor(::TextTerminal) = false
×
77

78
# Utility Functions
79
width(t::TextTerminal) = (displaysize(t)::Tuple{Int,Int})[2]
×
80
height(t::TextTerminal) = (displaysize(t)::Tuple{Int,Int})[1]
×
81

82
# For terminals with buffers
83
flush(t::TextTerminal) = nothing
×
84

85
clear(t::TextTerminal) = error("Unimplemented")
×
86
clear_line(t::TextTerminal, row) = error("Unimplemented")
×
87
clear_line(t::TextTerminal) = error("Unimplemented")
×
88

89
raw!(t::TextTerminal, raw::Bool) = error("Unimplemented")
×
90

91
beep(t::TextTerminal) = nothing
×
92
enable_bracketed_paste(t::TextTerminal) = nothing
×
93
disable_bracketed_paste(t::TextTerminal) = nothing
×
94

95
## UnixTerminal ##
96

97
abstract type UnixTerminal <: TextTerminal end
98

99
pipe_reader(t::UnixTerminal) = t.in_stream::IO
1✔
100
pipe_writer(t::UnixTerminal) = t.out_stream::IO
×
101

102
mutable struct TerminalBuffer <: UnixTerminal
103
    out_stream::IO
104
end
105

106
mutable struct TTYTerminal <: UnixTerminal
107
    term_type::String
888✔
108
    in_stream::IO
109
    out_stream::IO
110
    err_stream::IO
111
end
112

113
const CSI = "\x1b["
114

115
cmove_up(t::UnixTerminal, n) = write(t.out_stream, "$(CSI)$(n)A")
×
116
cmove_down(t::UnixTerminal, n) = write(t.out_stream, "$(CSI)$(n)B")
×
117
cmove_right(t::UnixTerminal, n) = write(t.out_stream, "$(CSI)$(n)C")
×
118
cmove_left(t::UnixTerminal, n) = write(t.out_stream, "$(CSI)$(n)D")
×
119
cmove_line_up(t::UnixTerminal, n) = (cmove_up(t, n); cmove_col(t, 1))
×
120
cmove_line_down(t::UnixTerminal, n) = (cmove_down(t, n); cmove_col(t, 1))
×
121
cmove_col(t::UnixTerminal, n) = (write(t.out_stream, '\r'); n > 1 && cmove_right(t, n-1))
×
122

123
const is_precompiling = Ref(false)
124
if Sys.iswindows()
125
    function raw!(t::TTYTerminal,raw::Bool)
×
126
        is_precompiling[] && return true
×
127
        check_open(t.in_stream)
×
128
        if Base.ispty(t.in_stream)
×
129
            run((raw ? `stty raw -echo onlcr -ocrnl opost` : `stty sane`),
×
130
                t.in_stream, t.out_stream, t.err_stream)
131
            true
×
132
        else
133
            ccall(:jl_tty_set_mode, Int32, (Ptr{Cvoid},Int32), t.in_stream.handle::Ptr{Cvoid}, raw) != -1
×
134
        end
135
    end
136
else
137
    function raw!(t::TTYTerminal, raw::Bool)
2✔
138
        check_open(t.in_stream)
2✔
139
        ccall(:jl_tty_set_mode, Int32, (Ptr{Cvoid},Int32), t.in_stream.handle::Ptr{Cvoid}, raw) != -1
2✔
140
    end
141
end
142

143
# eval some of these definitions to insert CSI as a constant string
144
@eval enable_bracketed_paste(t::UnixTerminal) = write(t.out_stream, $"$(CSI)?2004h")
×
145
@eval disable_bracketed_paste(t::UnixTerminal) = write(t.out_stream, $"$(CSI)?2004l")
×
146
@eval end_keypad_transmit_mode(t::UnixTerminal) = # tput rmkx
×
147
    write(t.out_stream, $"$(CSI)?1l\x1b>")
148

149
@eval clear(t::UnixTerminal) = write(t.out_stream, $"$(CSI)H$(CSI)2J")
×
150
@eval clear_line(t::UnixTerminal) = write(t.out_stream, $"\r$(CSI)0K")
×
151
beep(t::UnixTerminal) = write(t.err_stream,"\x7")
×
152

153
Base.displaysize(t::UnixTerminal) = displaysize(t.out_stream)
×
154

155
hascolor(t::TTYTerminal) = get(t.out_stream, :color, false)::Bool
×
156

157
# use cached value of have_color
158
Base.in(key_value::Pair, t::TTYTerminal) = in(key_value, pipe_writer(t))
×
159
Base.haskey(t::TTYTerminal, key) = haskey(pipe_writer(t), key)
×
160
Base.getindex(t::TTYTerminal, key) = getindex(pipe_writer(t), key)
×
161
Base.get(t::TTYTerminal, key, default) = get(pipe_writer(t), key, default)
×
162

163
Base.peek(t::TTYTerminal, ::Type{T}) where {T} = peek(t.in_stream, T)::T
×
164

165
end # module
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc