From 3fcb7e5c6faa208bffac7f14733a99f3ad5a12a4 Mon Sep 17 00:00:00 2001 From: Solderpunk Date: Sat, 8 Dec 2018 12:58:42 +0000 Subject: Reduce code duplication and needless function argument. --- telem.lua | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'telem.lua') diff --git a/telem.lua b/telem.lua index 4fd72e4..5b7ebbd 100755 --- a/telem.lua +++ b/telem.lua @@ -209,24 +209,21 @@ end function do_type_first() current_thread_index = 1 - do_type_show_post(current_thread_index) - print(string.format("Viewing post %d of %d in thread", current_thread_index, #current_thread_posts)) + do_type_show_post() end function do_type_next() if current_thread_index ~= #current_thread_posts then current_thread_index = current_thread_index + 1 end - do_type_show_post(current_thread_index) - print(string.format("Viewing post %d of %d in thread", current_thread_index, #current_thread_posts)) + do_type_show_post() end function do_type_prev() if current_thread_index ~= 1 then current_thread_index = current_thread_index - 1 end - do_type_show_post(current_thread_index) - print(string.format("Viewing post %d of %d in thread", current_thread_index, #current_thread_posts)) + do_type_show_post() end function do_type_reply() @@ -241,7 +238,7 @@ function do_type_reply() end current_thread_posts = get_posts(thread) current_thread_index = #current_thread_posts - do_type_show_post(current_thread_index) + do_type_show_post() end type_dispatch = {} @@ -262,8 +259,7 @@ function do_type() current_thread_subject = thread.subject current_thread_posts = get_posts(thread) current_thread_index = #current_thread_posts - do_type_show_post(current_thread_index) - print(string.format("Viewing post %d of %d in thread", current_thread_index, #current_thread_posts)) + do_type_show_post() repeat show_type_prompt() c = getchar() @@ -280,14 +276,15 @@ function show_type_prompt() io.write("[f]irst, [n]ext, [p]rev, [r]eply, [d]one > ") end -function do_type_show_post(index) - local post = current_thread_posts[index] +function do_type_show_post() + local post = current_thread_posts[current_thread_index] print("SUBJECT: " .. current_thread_subject) print("AUTHOR: " .. post.author) print("POSTED: " .. os.date("%H:%M %B %d, %Y", post.timestamp)) print("--------------------------------") cat_file(post.filename) print("--------------------------------") + print(string.format("Viewing post %d of %d in thread", current_thread_index, #current_thread_posts)) end function do_quit() -- cgit v1.2.3