#!/usr/bin/env murgaLua --[[ simple text display directed primarily toward high-res ASCII art mikshaw 2010 This program is free software. It comes without any warranty, to the extent permitted by applicable law. You can redistribute it and/or modify it under the terms of the Do What The Fuck You Want To Public License, Version 2, as published by Sam Hocevar. See http://sam.zoy.org/wtfpl/COPYING for more details. --]] -- preferences asciidir="." -- start directory --asciidir="/home/shared/image/ascii" sep="/" -- directory name separator, "\" for Windows ww,wh=720,486 -- main window width & height lw=140 -- file list width as=5 -- initial art text size fs_key="f" -- fullscreen hotkey big_key=">" -- art font bigger lil_key="<" -- font smaller next_key="." -- show next file prev_key="," -- show previous file cd_key="o" -- change directory swap_key="x" -- swap fg and bg colors -- OPTIONAL preferences, can be deleted or commented out ts=11 -- list text size Fl:set_boxtype(fltk.FL_UP_BOX,fltk.FL_THIN_UP_BOX) Fl:set_boxtype(fltk.FL_DOWN_BOX,fltk.FL_THIN_DOWN_BOX) Fl:scrollbar_size(10) -- scrollbar width --Fl:set_font(fltk.FL_COURIER_BOLD,"some font") -- ascii text font function load_txt() list:value(index) artbuff:loadfile(asciidir..filetab[index]) win:redraw() end -- file navigation function list_cb() if list:value()>0 then index=list:value() load_txt() end end function nav_dn() if index1 then index=index-1 load_txt() end end -- font size function refresh_buff() art:textsize(as) tmp=artbuff:text() artbuff:text(tmp) win:redraw() end function fnt_sm() if as>1 then as=as-1 refresh_buff() end end function fnt_lg() if as<24 then as=as+1 refresh_buff() end end -- swap colors function invert() fg,bg=art:color(),art:textcolor() art:textcolor(fg) art:color(bg) art:redraw() end -- fullscreen, kludged for dwm which doesn't like Fl_Window:fullscreen() function tog_fs() if fullscr==0 then list:hide() art:scrollbar_width(0) wx,wy,ww,wh=win:x(),win:y(),win:w(),win:h() win:resize(0,0,Fl:w(),Fl:h()) art:resize(0,0,Fl:w(),Fl:h()) fullscr=1 else list:show() art:scrollbar_width(Fl:scrollbar_size()) win:resize(wx,wy,ww,wh) art:resize(lw,0,ww-lw,wh) fullscr=0 end win:redraw() end --[[ -- normal fullscreen function tog_fs() if fullscr==0 then list:hide() wx,wy,ww,wh=win:x(),win:y(),win:w(),win:h() win:fullscreen() art:resize(0,0,Fl:w(),Fl:h()) fullscr=1 else list:show() win:fullscreen_off(wx,wy,ww,wh) art:resize(mw,0,ww-mw,wh) fullscr=0 end win:redraw() end --]] -- change directory function cd() local newdir=fltk.fl_dir_chooser("pick a new directory",asciidir,0) if newdir then asciidir=newdir get_files() end end -- add files to list function get_files() list:clear_output() filetab={} list:clear() if not string.find(asciidir,sep.."$") then asciidir=asciidir..sep end for i in lfs.dir(asciidir) do if string.find(string.lower(i),"%.txt$") then table.insert(filetab,i) end end table.sort(filetab) for i,v in pairs(filetab) do list:add(string.sub(v,1,-5)) end if list:size()==0 then list:add("no text files found") list:set_output() else list:value(1); list:do_callback() end end -- interface Fl:get_system_colors() win=fltk:Fl_Double_Window(ww,wh,"ASCII Images") -- files list=fltk:Fl_Hold_Browser(0,0,lw,wh) list:callback(list_cb) if ts then list:textsize(ts) end -- display area art=fltk:Fl_Text_Display(lw,0,ww-lw,wh) artbuff=fltk:Fl_Text_Buffer() art:buffer(artbuff) art:textfont(fltk.FL_COURIER) art:textsize(as) -- hotkeys hk=fltk:Fl_Menu_Bar(0,0,0,0) hk:add("fullscreen",string.byte(fs_key),tog_fs) hk:add("big",string.byte(big_key),fnt_lg) hk:add("little",string.byte(lil_key),fnt_sm) hk:add("next",string.byte(next_key),nav_dn) hk:add("prev",string.byte(prev_key),nav_up) hk:add("change directory",string.byte(cd_key),cd) hk:add("swap colors",string.byte(swap_key),invert) hk:global() index,fullscr=0,0 get_files() --win:resizable(art) win:show() Fl:run()