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

JuliaLang / julia / #38162

06 Aug 2025 08:25PM UTC coverage: 25.688% (-43.6%) from 69.336%
#38162

push

local

web-flow
fix runtime cglobal builtin function implementation (#59210)

This had failed to be updated for the LazyLibrary changes to codegen.

12976 of 50513 relevant lines covered (25.69%)

676965.51 hits per line

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

6.56
/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

35
## AbstractTerminal: abstract supertype of all terminals ##
36

37
abstract type AbstractTerminal <: Base.AbstractPipe end
38

39
## TextTerminal ##
40

41
abstract type TextTerminal <: AbstractTerminal end
42

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

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

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

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

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

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

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

71
cmove_col(t::TextTerminal, c) = cmove(c, getY(t))
×
72

73
# Defaults
74
hascolor(::TextTerminal) = false
×
75

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

80
# For terminals with buffers
81
flush(t::TextTerminal) = nothing
×
82

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

87
raw!(t::TextTerminal, raw::Bool) = error("Unimplemented")
×
88

89
beep(t::TextTerminal) = nothing
×
90
enable_bracketed_paste(t::TextTerminal) = nothing
×
91
disable_bracketed_paste(t::TextTerminal) = nothing
×
92

93
## UnixTerminal ##
94

95
abstract type UnixTerminal <: TextTerminal end
96

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

100
@nospecialize
101
mutable struct TerminalBuffer <: UnixTerminal
102
    out_stream::IO
103
end
104

105
mutable struct TTYTerminal <: UnixTerminal
106
    term_type::String
1✔
107
    in_stream::IO
108
    out_stream::IO
109
    err_stream::IO
110
end
111
@specialize
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
if Sys.iswindows()
124
    function raw!(t::TTYTerminal,raw::Bool)
×
125
        if Base.ispty(t.in_stream)
×
126
            run((raw ? `stty raw -echo onlcr -ocrnl opost` : `stty sane`),
×
127
                t.in_stream, t.out_stream, t.err_stream)
128
            true
×
129
        else
130
            ccall(:jl_tty_set_mode, Int32, (Ptr{Cvoid},Int32), t.in_stream.handle::Ptr{Cvoid}, raw) == 0
×
131
        end
132
    end
133
else
134
    function raw!(t::TTYTerminal, raw::Bool)
2✔
135
        ccall(:jl_tty_set_mode, Int32, (Ptr{Cvoid},Int32), t.in_stream.handle::Ptr{Cvoid}, raw) == 0
2✔
136
    end
137
end
138

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

145
@eval clear(t::UnixTerminal) = write(t.out_stream, $"$(CSI)H$(CSI)2J")
×
146
@eval clear_line(t::UnixTerminal) = write(t.out_stream, $"\r$(CSI)0K")
×
147
beep(t::UnixTerminal) = write(t.err_stream,"\x7")
×
148

149
Base.displaysize(t::UnixTerminal) = displaysize(t.out_stream)::Tuple{Int,Int}
×
150

151
hascolor(t::TTYTerminal) = get(t.out_stream, :color, false)::Bool
×
152

153
# use cached value of have_color
154
Base.in(key_value::Pair, t::TTYTerminal) = in(key_value, pipe_writer(t))
×
155
Base.haskey(t::TTYTerminal, key) = haskey(pipe_writer(t), key)
×
156
Base.getindex(t::TTYTerminal, key) = getindex(pipe_writer(t), key)
×
157
Base.get(t::TTYTerminal, key, default) = get(pipe_writer(t), key, default)
×
158

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

161
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

© 2026 Coveralls, Inc