News : The level of daily SPAM has reached insane proportions, all registrations are now manual. I ask you to send me an e-mail (john (at) murga (dot) org), to confirm that you want me to create an account for you.


Post Reply  Post Thread 
ascii art viewer
Author Message
mikshaw
Senior Member
****


Posts: 522
Group: Registered
Joined: Apr 2007
Status: Offline
Reputation: 5
Post: #1
RE: ascii art viewer

I think I might have fixed it. Having two menu items using the same callback was somehow causing trouble....most likely me not handling the concept properly.

Added change directory ("c" key), and as a result had to include a directory separator (sep) because depending on how you select with the fl_dir_chooser you may or may not end up with a trailing slash. I have no idea if this willwork as-is in windows. Is now also case-insensitive so it won't ignore *.TXT or *.Txt

Code:
#!/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.

--]]


asciidir="/home/shared/image/ascii"
sep="/" -- "\" for Windows
Fl:set_font(fltk.FL_SCREEN,"mono")
Fl:set_boxtype(fltk.FL_UP_BOX,fltk.FL_THIN_UP_BOX)
Fl:set_boxtype(fltk.FL_DOWN_BOX,fltk.FL_THIN_DOWN_BOX)
ts=11 -- list txt size

ww,wh,mw,index,fullscr=720,486,140,0,0
win=fltk:Fl_Double_Window(ww,wh,"ASCII Images")

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 index<list:size() then
  index=index+1
  load_txt()
end
end
function nav_up()
if index>1 then
  index=index-1
  load_txt()
end
end

-- font size
function refresh_buff()
tmp=artbuff:text()
artbuff:text(tmp)
win:redraw()
end
function fnt_sm()
if art:textsize()>1 then
  art:textsize(art:textsize()-1)
  refresh_buff()
end
end
function fnt_lg()
if art:textsize()<16 then
  art:textsize(art:textsize()+1)
  refresh_buff()
end
end

-- fullscreen, kludged for dwm which doesn't like Fl_Window:fullscreen()
function tog_fs()
if fullscr==0 then
  list:hide()
  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()
  win:resize(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

-- files
list=fltk:Fl_Hold_Browser(0,0,mw,wh)
list:callback(list_cb)
if ts then list:textsize(ts) end

-- display area
art=fltk:Fl_Text_Display(mw,0,ww-mw,wh)
artbuff=fltk:Fl_Text_Buffer()
art:buffer(artbuff)
art:textfont(fltk.FL_SCREEN)
art:textsize(5)

-- hotkeys
hk=fltk:Fl_Menu_Bar(0,0,0,0)
hk:add("fullscreen",string.byte("f"),tog_fs)
hk:add("big",string.byte(">"),fnt_lg)
hk:add("little",string.byte("<"),fnt_sm)
hk:add("next",string.byte("."),nav_dn)
hk:add("prev",string.byte(","),nav_up)
hk:add("change directory",string.byte("c"),cd)
hk:global()

get_files()
win:resizable(art)
win:show()
Fl:run()

This post was last modified: 12-05-2010 04:48 PM by mikshaw.

12-05-2010 02:30 PM
Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

Messages In This Thread
ascii art viewer - mikshaw - 12-05-2010, 06:02 AM
RE: ascii art viewer - jpjacobs - 12-05-2010, 06:42 AM
RE: ascii art viewer - mikshaw - 12-05-2010, 08:20 AM
RE: ascii art viewer - mikshaw - 12-05-2010, 09:43 AM
RE: ascii art viewer - mikshaw - 12-05-2010 02:30 PM
RE: ascii art viewer - jpjacobs - 12-05-2010, 11:30 PM
RE: ascii art viewer - mikshaw - 12-06-2010, 01:25 AM
RE: ascii art viewer - mikshaw - 12-06-2010, 01:44 AM
RE: ascii art viewer - mikshaw - 12-08-2010, 03:53 AM

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites

Forum Jump: