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

JuliaLang / julia / #37900

11 Sep 2024 03:35AM UTC coverage: 87.734% (-0.02%) from 87.749%
#37900

push

local

web-flow
Fix "Various fixes to byte / bytearray search"  (#55734)

Fixes the conflict between #54593 and #54579
`_search` returns `nothing` instead of zero as a sentinal in #54579

1 of 1 new or added line in 1 file covered. (100.0%)

445 existing lines in 6 files now uncovered.

78467 of 89437 relevant lines covered (87.73%)

16661238.23 hits per line

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

34.38
/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)
1,210✔
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]
4,362✔
78
height(t::TextTerminal) = (displaysize(t)::Tuple{Int,Int})[1]
2,096✔
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
10,287✔
98
pipe_writer(t::UnixTerminal) = t.out_stream::IO
20,344✔
99

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

105
mutable struct TTYTerminal <: UnixTerminal
106
    term_type::String
17✔
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")
1,250✔
116
cmove_down(t::UnixTerminal, n) = write(t.out_stream, "$(CSI)$(n)B")
41✔
117
cmove_right(t::UnixTerminal, n) = write(t.out_stream, "$(CSI)$(n)C")
4,451✔
118
cmove_left(t::UnixTerminal, n) = write(t.out_stream, "$(CSI)$(n)D")
597✔
UNCOV
119
cmove_line_up(t::UnixTerminal, n) = (cmove_up(t, n); cmove_col(t, 1))
×
UNCOV
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))
4,473✔
122

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

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

147
@eval clear(t::UnixTerminal) = write(t.out_stream, $"$(CSI)H$(CSI)2J")
×
148
@eval clear_line(t::UnixTerminal) = write(t.out_stream, $"\r$(CSI)0K")
3,594✔
UNCOV
149
beep(t::UnixTerminal) = write(t.err_stream,"\x7")
×
150

151
Base.displaysize(t::UnixTerminal) = displaysize(t.out_stream)
6,536✔
152

UNCOV
153
hascolor(t::TTYTerminal) = get(t.out_stream, :color, false)::Bool
×
154

155
# use cached value of have_color
156
Base.in(key_value::Pair, t::TTYTerminal) = in(key_value, pipe_writer(t))
2✔
157
Base.haskey(t::TTYTerminal, key) = haskey(pipe_writer(t), key)
2✔
158
Base.getindex(t::TTYTerminal, key) = getindex(pipe_writer(t), key)
2✔
159
Base.get(t::TTYTerminal, key, default) = get(pipe_writer(t), key, default)
8✔
160

UNCOV
161
Base.peek(t::TTYTerminal, ::Type{T}) where {T} = peek(t.in_stream, T)::T
×
162

163
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