Skip to content

Commit

Permalink
🔧 Minor code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ronisbr committed Nov 15, 2024
1 parent 088bc66 commit e0a6bb0
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 17 deletions.
1 change: 0 additions & 1 deletion src/command_line.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ function _redraw_cmd_line!(pagerd::Pager)

elseif mode == :searching
active_search_match_id = pagerd.active_search_match_id
search_matches = pagerd.search_matches
num_matches = pagerd.num_matches

# Check if there are matches.
Expand Down
16 changes: 7 additions & 9 deletions src/pager.jl
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ function _pager_key_process!(pagerd::Pager, k::Keystroke)
visual_mode = pagerd.visual_mode
visual_mode_line = pagerd.visual_mode_line

redraw = false
event = nothing
key = (k.value, k.alt, k.ctrl, k.shift)
action = get(_KEYBINDINGS, key, nothing)
Expand Down Expand Up @@ -486,7 +485,6 @@ end
# Process the event in `pagerd`. If this function return `false`, the application must exit.
function _pager_event_process!(pagerd::Pager)
event = pagerd.event
lines = pagerd.lines

# For EOT (^D), we will implement two types of "quit" action. If we are in searching
# mode, exit it. If not, quit the pager.
Expand Down Expand Up @@ -536,15 +534,15 @@ function _pager_event_process!(pagerd::Pager)
)
frozen_rows = tryparse(Int, cmd_input; base = 10)

if (frozen_rows == nothing) && !isempty(cmd_input)
if isnothing(frozen_rows) && !isempty(cmd_input)
_print_cmd_message!(
pagerd,
"Invalid data!";
crayon = crayon"red bold"
)
_jlgetch(pagerd.term.in_stream)
else
if frozen_rows != nothing
if !isnothing(frozen_rows)
pagerd.frozen_rows = max(0, frozen_rows)
pagerd.start_row = max(pagerd.start_row, frozen_rows + 1)
pagerd.visual_mode_line = 1
Expand All @@ -556,14 +554,14 @@ function _pager_event_process!(pagerd::Pager)
)
frozen_columns = tryparse(Int, cmd_input; base = 10)

if (frozen_columns == nothing) && !isempty(cmd_input)
if isnothing(frozen_columns) && !isempty(cmd_input)
_print_cmd_message!(
pagerd, "Invalid data!";
crayon = crayon"red bold"
)
_jlgetch(pagerd.term.in_stream)

elseif frozen_columns != nothing
elseif !isnothing(frozen_columns)
pagerd.frozen_columns = max(0, frozen_columns)
pagerd.start_column = max(pagerd.start_column, frozen_columns + 1)
end
Expand All @@ -578,15 +576,15 @@ function _pager_event_process!(pagerd::Pager)
)
title_rows = tryparse(Int, cmd_input; base = 10)

if (title_rows == nothing) && !isempty(cmd_input)
if isnothing(title_rows) && !isempty(cmd_input)
_print_cmd_message!(
pagerd,
"Invalid data!";
crayon = crayon"red bold"
)
_jlgetch(pagerd.term.in_stream)
else
title_rows != nothing && (pagerd.title_rows = max(0, title_rows))
elseif !isnothing(title_rows)
pagerd.title_rows = max(0, title_rows)
end

_request_redraw!(pagerd)
Expand Down
4 changes: 2 additions & 2 deletions src/repl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,12 @@ function _tp_mode_do_cmd(repl::REPL.AbstractREPL, input::String)
is_error = false

# Loop through the lines.
@inbounds for i in 1:length(lines)
@inbounds for i in eachindex(lines)
cmd *= lines[i] * "\n"
ast = Base.parse_input_line(cmd)

# If the command is incomplete, we need to wait for another line.
ast !== nothing && ast.head == :incomplete && continue
!isnothing(ast) && ast.head == :incomplete && continue

# We will use `REPL.eval_with_backend` to evaluate the expression. This function
# returns two values: the object returned by the expression, and a boolean value
Expand Down
5 changes: 1 addition & 4 deletions src/search.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@
# Change the active matches in `pagerd`. If `forward` is `true`, the search is performed
# forward. Otherwise, it is performed backwards.
function _change_active_match!(pagerd::Pager, forward::Bool = true)
search_matches = pagerd.search_matches
active_search_match_id = pagerd.active_search_match_id
num_matches = pagerd.num_matches

if num_matches == 0
active_number_match = 0
else
if num_matches != 0
# Activate the next match according to the user preference.
if forward
active_search_match_id += 1
Expand Down
1 change: 0 additions & 1 deletion src/view.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ function _view!(pagerd::Pager)
frozen_columns = pagerd.frozen_columns
frozen_rows = pagerd.frozen_rows
lines = pagerd.lines
num_lines = pagerd.num_lines
search_matches = pagerd.search_matches
show_ruler = pagerd.show_ruler
start_column = pagerd.start_column
Expand Down

0 comments on commit e0a6bb0

Please sign in to comment.