reject crlf embrace lf
This commit is contained in:
parent
b52fdf512c
commit
c1d109e198
1 changed files with 498 additions and 498 deletions
996
cimp.bas
996
cimp.bas
|
|
@ -1,498 +1,498 @@
|
||||||
declare library "terminkey"
|
declare library "terminkey"
|
||||||
function terminkey%()
|
function terminkey%()
|
||||||
sub echooff()
|
sub echooff()
|
||||||
sub echoon()
|
sub echoon()
|
||||||
function termwidth()
|
function termwidth()
|
||||||
end declare
|
end declare
|
||||||
|
|
||||||
$console:only
|
$console:only
|
||||||
on error goto quit
|
on error goto quit
|
||||||
const KEY_UP = 1001
|
const KEY_UP = 1001
|
||||||
const KEY_DOWN = 1002
|
const KEY_DOWN = 1002
|
||||||
const KEY_RIGHT = 1003
|
const KEY_RIGHT = 1003
|
||||||
const KEY_LEFT = 1004
|
const KEY_LEFT = 1004
|
||||||
|
|
||||||
$if WIN then
|
$if WIN then
|
||||||
Shell "chcp 65001 > nul"
|
Shell "chcp 65001 > nul"
|
||||||
$end if
|
$end if
|
||||||
|
|
||||||
redim file(0) as string
|
redim file(0) as string
|
||||||
if command$ = "" then
|
if command$ = "" then
|
||||||
print "please specify file to play."
|
print "please specify file to play."
|
||||||
goto quit
|
goto quit
|
||||||
end if
|
end if
|
||||||
|
|
||||||
echooff
|
echooff
|
||||||
cursoroff
|
cursoroff
|
||||||
chdir _startdir$
|
chdir _startdir$
|
||||||
|
|
||||||
dim volume as single
|
dim volume as single
|
||||||
dim repeat as integer
|
dim repeat as integer
|
||||||
dim shuffle as integer
|
dim shuffle as integer
|
||||||
dim nooutput as integer
|
dim nooutput as integer
|
||||||
dim timevis as integer
|
dim timevis as integer
|
||||||
dim nyan as integer
|
dim nyan as integer
|
||||||
dim marqueeOffset as integer
|
dim marqueeOffset as integer
|
||||||
dim i as integer
|
dim i as integer
|
||||||
|
|
||||||
dim musichandle as long
|
dim musichandle as long
|
||||||
dim oldhandle as long
|
dim oldhandle as long
|
||||||
dim keyin as integer
|
dim keyin as integer
|
||||||
dim playnext as integer
|
dim playnext as integer
|
||||||
|
|
||||||
dim state as string
|
dim state as string
|
||||||
dim songname as string
|
dim songname as string
|
||||||
dim progress as string
|
dim progress as string
|
||||||
dim progressbar as string
|
dim progressbar as string
|
||||||
|
|
||||||
dim tw as integer
|
dim tw as integer
|
||||||
dim fixedWidth as integer
|
dim fixedWidth as integer
|
||||||
dim maxTitleWidth as integer
|
dim maxTitleWidth as integer
|
||||||
dim visibleTitle as string
|
dim visibleTitle as string
|
||||||
dim currentSongWidth as integer
|
dim currentSongWidth as integer
|
||||||
dim paddedTitle as string
|
dim paddedTitle as string
|
||||||
dim paddedLength as integer
|
dim paddedLength as integer
|
||||||
dim idx as integer
|
dim idx as integer
|
||||||
dim addedWidth as integer
|
dim addedWidth as integer
|
||||||
dim charIdx as integer
|
dim charIdx as integer
|
||||||
dim nextChar as string
|
dim nextChar as string
|
||||||
dim marqueeFrame as integer
|
dim marqueeFrame as integer
|
||||||
|
|
||||||
volume=1
|
volume=1
|
||||||
repeat=0
|
repeat=0
|
||||||
shuffle=0
|
shuffle=0
|
||||||
nooutput=0
|
nooutput=0
|
||||||
timevis=1
|
timevis=1
|
||||||
nyan=0
|
nyan=0
|
||||||
marqueeOffset=0
|
marqueeOffset=0
|
||||||
|
|
||||||
for i=1 to _commandcount
|
for i=1 to _commandcount
|
||||||
select case command$(i)
|
select case command$(i)
|
||||||
case "-v", "--volume"
|
case "-v", "--volume"
|
||||||
i=i+1
|
i=i+1
|
||||||
volume=val(command$(i)) / 100
|
volume=val(command$(i)) / 100
|
||||||
case "-s","--shuffle"
|
case "-s","--shuffle"
|
||||||
shuffle=-1
|
shuffle=-1
|
||||||
case "-r","--repeat"
|
case "-r","--repeat"
|
||||||
if command$(i+1)="1" then
|
if command$(i+1)="1" then
|
||||||
repeat=1
|
repeat=1
|
||||||
else
|
else
|
||||||
repeat=-1
|
repeat=-1
|
||||||
end if
|
end if
|
||||||
case "-n","--nooutput"
|
case "-n","--nooutput"
|
||||||
nooutput=-1
|
nooutput=-1
|
||||||
case "-N","--nyan"
|
case "-N","--nyan"
|
||||||
nyan=-1
|
nyan=-1
|
||||||
case else
|
case else
|
||||||
if _fileexists(command$(i)) then
|
if _fileexists(command$(i)) then
|
||||||
if lcase$(right$(command$(i), 4))=".m3u" then
|
if lcase$(right$(command$(i), 4))=".m3u" then
|
||||||
ParseM3U command$(i),file()
|
ParseM3U command$(i),file()
|
||||||
else
|
else
|
||||||
file(ubound(file))=command$(i)
|
file(ubound(file))=command$(i)
|
||||||
redim _preserve file(ubound(file)+1)
|
redim _preserve file(ubound(file)+1)
|
||||||
end if
|
end if
|
||||||
end if
|
end if
|
||||||
end select
|
end select
|
||||||
next
|
next
|
||||||
|
|
||||||
redim _preserve file(ubound(file)-1)
|
redim _preserve file(ubound(file)-1)
|
||||||
|
|
||||||
if shuffle=-1 then shufflearray file()
|
if shuffle=-1 then shufflearray file()
|
||||||
i=0
|
i=0
|
||||||
musichandle = _sndopen(file(i))
|
musichandle = _sndopen(file(i))
|
||||||
if musichandle = 0 then
|
if musichandle = 0 then
|
||||||
print "Error: could not open file "; file(i)
|
print "Error: could not open file "; file(i)
|
||||||
goto quit
|
goto quit
|
||||||
end if
|
end if
|
||||||
_sndvol musichandle, volume
|
_sndvol musichandle, volume
|
||||||
_sndplay musichandle
|
_sndplay musichandle
|
||||||
state = "playing "
|
state = "playing "
|
||||||
songname = beforelast(".", afterlast("/", file(i)))
|
songname = beforelast(".", afterlast("/", file(i)))
|
||||||
|
|
||||||
while keyin <> 27
|
while keyin <> 27
|
||||||
keyin = terminkey
|
keyin = terminkey
|
||||||
select case keyin
|
select case keyin
|
||||||
case KEY_UP
|
case KEY_UP
|
||||||
volume = volume + (0.01 + (volume / 10))
|
volume = volume + (0.01 + (volume / 10))
|
||||||
if volume > 1 then volume = 1
|
if volume > 1 then volume = 1
|
||||||
_sndvol musichandle, volume
|
_sndvol musichandle, volume
|
||||||
case KEY_DOWN
|
case KEY_DOWN
|
||||||
volume = volume - (0.01 + (volume / 10))
|
volume = volume - (0.01 + (volume / 10))
|
||||||
if volume < 0 then volume = 0
|
if volume < 0 then volume = 0
|
||||||
_sndvol musichandle, volume
|
_sndvol musichandle, volume
|
||||||
case KEY_RIGHT
|
case KEY_RIGHT
|
||||||
if _sndgetpos(musichandle) + 5 < _sndlen(musichandle) then
|
if _sndgetpos(musichandle) + 5 < _sndlen(musichandle) then
|
||||||
_sndsetpos musichandle, _sndgetpos(musichandle) + 5
|
_sndsetpos musichandle, _sndgetpos(musichandle) + 5
|
||||||
else
|
else
|
||||||
playnext = 1
|
playnext = 1
|
||||||
end if
|
end if
|
||||||
case KEY_LEFT
|
case KEY_LEFT
|
||||||
if _sndgetpos(musichandle) - 5 > 0 then
|
if _sndgetpos(musichandle) - 5 > 0 then
|
||||||
_sndsetpos musichandle, _sndgetpos(musichandle) - 5
|
_sndsetpos musichandle, _sndgetpos(musichandle) - 5
|
||||||
else
|
else
|
||||||
playnext = -1
|
playnext = -1
|
||||||
end if
|
end if
|
||||||
case asc("q")
|
case asc("q")
|
||||||
keyin = 27
|
keyin = 27
|
||||||
case asc("z")
|
case asc("z")
|
||||||
if _sndgetpos(musichandle) > 2 then
|
if _sndgetpos(musichandle) > 2 then
|
||||||
_sndsetpos musichandle, 0
|
_sndsetpos musichandle, 0
|
||||||
else
|
else
|
||||||
playnext = -1
|
playnext = -1
|
||||||
end if
|
end if
|
||||||
case asc("x")
|
case asc("x")
|
||||||
if _sndplaying(musichandle) then
|
if _sndplaying(musichandle) then
|
||||||
_sndsetpos musichandle, 0
|
_sndsetpos musichandle, 0
|
||||||
else
|
else
|
||||||
_sndplay musichandle
|
_sndplay musichandle
|
||||||
end if
|
end if
|
||||||
case asc("c"), asc(" ")
|
case asc("c"), asc(" ")
|
||||||
if _sndplaying(musichandle) then
|
if _sndplaying(musichandle) then
|
||||||
_sndpause musichandle
|
_sndpause musichandle
|
||||||
state = "paused "
|
state = "paused "
|
||||||
else
|
else
|
||||||
_sndplay musichandle
|
_sndplay musichandle
|
||||||
state = "playing "
|
state = "playing "
|
||||||
end if
|
end if
|
||||||
case asc("v")
|
case asc("v")
|
||||||
_sndstop musichandle
|
_sndstop musichandle
|
||||||
state = "stopped "
|
state = "stopped "
|
||||||
case asc("b")
|
case asc("b")
|
||||||
playnext = 1
|
playnext = 1
|
||||||
case asc("t")
|
case asc("t")
|
||||||
timevis = -timevis
|
timevis = -timevis
|
||||||
case asc("s")
|
case asc("s")
|
||||||
shufflearray file()
|
shufflearray file()
|
||||||
end select
|
end select
|
||||||
|
|
||||||
if _sndgetpos(musichandle) = _sndlen(musichandle) then playnext = 1
|
if _sndgetpos(musichandle) = _sndlen(musichandle) then playnext = 1
|
||||||
if playnext <> 0 then
|
if playnext <> 0 then
|
||||||
oldhandle = musichandle
|
oldhandle = musichandle
|
||||||
if repeat = 1 and playnext = 1 then
|
if repeat = 1 and playnext = 1 then
|
||||||
playnext = 0
|
playnext = 0
|
||||||
else
|
else
|
||||||
i = i + playnext
|
i = i + playnext
|
||||||
if i > ubound(file) then
|
if i > ubound(file) then
|
||||||
if repeat = -1 then
|
if repeat = -1 then
|
||||||
i = 0
|
i = 0
|
||||||
else
|
else
|
||||||
goto quit
|
goto quit
|
||||||
end if
|
end if
|
||||||
elseif i < lbound(file) then
|
elseif i < lbound(file) then
|
||||||
if repeat = -1 then
|
if repeat = -1 then
|
||||||
i = ubound(file)
|
i = ubound(file)
|
||||||
else
|
else
|
||||||
i = lbound(file)
|
i = lbound(file)
|
||||||
end if
|
end if
|
||||||
end if
|
end if
|
||||||
end if
|
end if
|
||||||
musichandle = _sndopen(file(i))
|
musichandle = _sndopen(file(i))
|
||||||
if musichandle <> 0 then
|
if musichandle <> 0 then
|
||||||
_sndvol musichandle, volume
|
_sndvol musichandle, volume
|
||||||
_sndplay musichandle
|
_sndplay musichandle
|
||||||
_sndstop oldhandle
|
_sndstop oldhandle
|
||||||
_sndclose oldhandle
|
_sndclose oldhandle
|
||||||
state = "playing "
|
state = "playing "
|
||||||
songname = beforelast(".", afterlast("/", file(i)))
|
songname = beforelast(".", afterlast("/", file(i)))
|
||||||
playnext = 0
|
playnext = 0
|
||||||
else
|
else
|
||||||
musichandle = oldhandle
|
musichandle = oldhandle
|
||||||
end if
|
end if
|
||||||
end if
|
end if
|
||||||
|
|
||||||
if timevis = 1 then
|
if timevis = 1 then
|
||||||
progress = " -" + timeleft(musichandle)
|
progress = " -" + timeleft(musichandle)
|
||||||
else
|
else
|
||||||
progress = " " + timeelapsed(musichandle)
|
progress = " " + timeelapsed(musichandle)
|
||||||
end if
|
end if
|
||||||
if nooutput = 0 then
|
if nooutput = 0 then
|
||||||
tw = termwidth
|
tw = termwidth
|
||||||
fixedWidth = UWidth(state) + UWidth(progress)
|
fixedWidth = UWidth(state) + UWidth(progress)
|
||||||
maxTitleWidth = tw - fixedWidth - 2
|
maxTitleWidth = tw - fixedWidth - 2
|
||||||
currentSongWidth = UWidth(songname)
|
currentSongWidth = UWidth(songname)
|
||||||
|
|
||||||
if currentSongWidth > maxTitleWidth and maxTitleWidth > 4 then
|
if currentSongWidth > maxTitleWidth and maxTitleWidth > 4 then
|
||||||
paddedTitle = songname + " "
|
paddedTitle = songname + " "
|
||||||
paddedLength = ulen(paddedTitle)
|
paddedLength = ulen(paddedTitle)
|
||||||
visibleTitle = ""
|
visibleTitle = ""
|
||||||
addedWidth = 0
|
addedWidth = 0
|
||||||
idx = 0
|
idx = 0
|
||||||
while addedWidth < maxTitleWidth
|
while addedWidth < maxTitleWidth
|
||||||
charIdx = ((marqueeOffset + idx) mod paddedLength) + 1
|
charIdx = ((marqueeOffset + idx) mod paddedLength) + 1
|
||||||
nextChar = umid(paddedTitle, charIdx, 1)
|
nextChar = umid(paddedTitle, charIdx, 1)
|
||||||
if addedWidth + UWidth(nextChar) > maxTitleWidth then exit while
|
if addedWidth + UWidth(nextChar) > maxTitleWidth then exit while
|
||||||
visibleTitle = visibleTitle + nextChar
|
visibleTitle = visibleTitle + nextChar
|
||||||
addedWidth = addedWidth + UWidth(nextChar)
|
addedWidth = addedWidth + UWidth(nextChar)
|
||||||
idx = idx + 1
|
idx = idx + 1
|
||||||
wend
|
wend
|
||||||
|
|
||||||
if addedWidth < maxTitleWidth then
|
if addedWidth < maxTitleWidth then
|
||||||
visibleTitle = visibleTitle + space$(maxTitleWidth - addedWidth)
|
visibleTitle = visibleTitle + space$(maxTitleWidth - addedWidth)
|
||||||
end if
|
end if
|
||||||
|
|
||||||
marqueeFrame = marqueeFrame + 1
|
marqueeFrame = marqueeFrame + 1
|
||||||
if marqueeFrame mod 4 = 0 then
|
if marqueeFrame mod 4 = 0 then
|
||||||
marqueeOffset = marqueeOffset + 1
|
marqueeOffset = marqueeOffset + 1
|
||||||
if marqueeOffset >= paddedLength then marqueeOffset = 0
|
if marqueeOffset >= paddedLength then marqueeOffset = 0
|
||||||
end if
|
end if
|
||||||
else
|
else
|
||||||
' Terminal is wide enough, no scrolling needed
|
' Terminal is wide enough, no scrolling needed
|
||||||
visibleTitle = songname
|
visibleTitle = songname
|
||||||
marqueeOffset = 0
|
marqueeOffset = 0
|
||||||
end if
|
end if
|
||||||
|
|
||||||
' Reset marquee offset if song changes
|
' Reset marquee offset if song changes
|
||||||
if playnext <> 0 then marqueeOffset = 0
|
if playnext <> 0 then marqueeOffset = 0
|
||||||
|
|
||||||
' Print the text line
|
' Print the text line
|
||||||
if nyan = -1 then
|
if nyan = -1 then
|
||||||
print termcolor(7); state; AnimatedRainbowText(visibleTitle); termcolor(7); progress; clearrest
|
print termcolor(7); state; AnimatedRainbowText(visibleTitle); termcolor(7); progress; clearrest
|
||||||
else
|
else
|
||||||
print termcolor(7); state; termcolor(3); visibleTitle; termcolor(7); progress; clearrest
|
print termcolor(7); state; termcolor(3); visibleTitle; termcolor(7); progress; clearrest
|
||||||
end if
|
end if
|
||||||
|
|
||||||
' Generate and print progress bar matching the layout width
|
' Generate and print progress bar matching the layout width
|
||||||
progressbar = bar(UWidth(state) + UWidth(visibleTitle) + UWidth(progress), (_sndgetpos(musichandle) / _sndlen(musichandle)) * 100, 11, 7)
|
progressbar = bar(UWidth(state) + UWidth(visibleTitle) + UWidth(progress), (_sndgetpos(musichandle) / _sndlen(musichandle)) * 100, 11, 7)
|
||||||
print progressbar; clearrest; cursorback;
|
print progressbar; clearrest; cursorback;
|
||||||
end if
|
end if
|
||||||
|
|
||||||
_limit 30
|
_limit 30
|
||||||
if _exit then goto quit
|
if _exit then goto quit
|
||||||
wend
|
wend
|
||||||
|
|
||||||
quit:
|
quit:
|
||||||
_sndclose musichandle
|
_sndclose musichandle
|
||||||
print clearrest
|
print clearrest
|
||||||
print clearrest;
|
print clearrest;
|
||||||
print cursorback;
|
print cursorback;
|
||||||
print chr$(27) + "[0m";
|
print chr$(27) + "[0m";
|
||||||
cursoron
|
cursoron
|
||||||
echoon
|
echoon
|
||||||
system
|
system
|
||||||
|
|
||||||
sub shufflearray (stringarray() as string)
|
sub shufflearray (stringarray() as string)
|
||||||
randomize timer
|
randomize timer
|
||||||
dim n as long, j as long
|
dim n as long, j as long
|
||||||
for n = ubound(stringarray) to 1 step -1
|
for n = ubound(stringarray) to 1 step -1
|
||||||
j = int(rnd * n)
|
j = int(rnd * n)
|
||||||
swap stringarray(n), stringarray(j)
|
swap stringarray(n), stringarray(j)
|
||||||
next
|
next
|
||||||
end sub
|
end sub
|
||||||
|
|
||||||
sub ParseM3U (filename$, array$())
|
sub ParseM3U (filename$, array$())
|
||||||
dim i as long, f as long, count as long
|
dim i as long, f as long, count as long
|
||||||
dim basePath$, l$, resolvedPath$
|
dim basePath$, l$, resolvedPath$
|
||||||
for i = len(filename$) to 1 step -1
|
for i = len(filename$) to 1 step -1
|
||||||
if mid$(filename$, i, 1) = "/" or mid$(filename$, i, 1) = "\" then
|
if mid$(filename$, i, 1) = "/" or mid$(filename$, i, 1) = "\" then
|
||||||
basePath$ = left$(filename$, i)
|
basePath$ = left$(filename$, i)
|
||||||
exit for
|
exit for
|
||||||
end if
|
end if
|
||||||
next
|
next
|
||||||
f = freefile
|
f = freefile
|
||||||
open filename$ for input as #f
|
open filename$ for input as #f
|
||||||
count = 0
|
count = 0
|
||||||
do until eof(f)
|
do until eof(f)
|
||||||
line input #f, l$
|
line input #f, l$
|
||||||
l$ = _trim$(l$)
|
l$ = _trim$(l$)
|
||||||
if len(l$) > 0 and left$(l$, 1) <> "#" then
|
if len(l$) > 0 and left$(l$, 1) <> "#" then
|
||||||
resolvedPath$ = l$
|
resolvedPath$ = l$
|
||||||
if not _fileexists(resolvedPath$) then
|
if not _fileexists(resolvedPath$) then
|
||||||
resolvedPath$ = basePath$ + l$
|
resolvedPath$ = basePath$ + l$
|
||||||
end if
|
end if
|
||||||
if _fileexists(resolvedPath$) then
|
if _fileexists(resolvedPath$) then
|
||||||
array$(ubound(array$)) = resolvedPath$
|
array$(ubound(array$)) = resolvedPath$
|
||||||
redim _preserve array$(ubound(array$) + 1)
|
redim _preserve array$(ubound(array$) + 1)
|
||||||
end if
|
end if
|
||||||
end if
|
end if
|
||||||
loop
|
loop
|
||||||
close #f
|
close #f
|
||||||
end sub
|
end sub
|
||||||
|
|
||||||
function timeleft$ (handle&)
|
function timeleft$ (handle&)
|
||||||
dim seconds as integer
|
dim seconds as integer
|
||||||
seconds = _sndlen(handle&) - _sndgetpos(handle&)
|
seconds = _sndlen(handle&) - _sndgetpos(handle&)
|
||||||
if seconds < 0 then seconds = 0
|
if seconds < 0 then seconds = 0
|
||||||
timeleft$ = right$("0" + ltrim$(str$(seconds \ 60)), 2) + ":" + right$("0" + ltrim$(str$(seconds mod 60)), 2)
|
timeleft$ = right$("0" + ltrim$(str$(seconds \ 60)), 2) + ":" + right$("0" + ltrim$(str$(seconds mod 60)), 2)
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function timeelapsed$ (handle&)
|
function timeelapsed$ (handle&)
|
||||||
dim seconds as integer
|
dim seconds as integer
|
||||||
seconds = _sndgetpos(handle&)
|
seconds = _sndgetpos(handle&)
|
||||||
if seconds < 0 then seconds = 0
|
if seconds < 0 then seconds = 0
|
||||||
timeelapsed$ = right$("0" + ltrim$(str$(seconds \ 60)), 2) + ":" + right$("0" + ltrim$(str$(seconds mod 60)), 2)
|
timeelapsed$ = right$("0" + ltrim$(str$(seconds \ 60)), 2) + ":" + right$("0" + ltrim$(str$(seconds mod 60)), 2)
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function termcolor$ (colorvalue as _unsigned long)
|
function termcolor$ (colorvalue as _unsigned long)
|
||||||
select case colorvalue
|
select case colorvalue
|
||||||
case 0 to 7
|
case 0 to 7
|
||||||
termcolor = chr$(27) + "[0;3" + _trim$(str$(colorvalue)) + "m"
|
termcolor = chr$(27) + "[0;3" + _trim$(str$(colorvalue)) + "m"
|
||||||
case 8 to 15
|
case 8 to 15
|
||||||
termcolor = chr$(27) + "[1;3" + _trim$(str$(colorvalue - 8)) + "m"
|
termcolor = chr$(27) + "[1;3" + _trim$(str$(colorvalue - 8)) + "m"
|
||||||
case 16 to 255
|
case 16 to 255
|
||||||
termcolor = chr$(27) + "[38;5;" + _trim$(str$(colorvalue)) + "m"
|
termcolor = chr$(27) + "[38;5;" + _trim$(str$(colorvalue)) + "m"
|
||||||
case is > 255
|
case is > 255
|
||||||
termcolor = chr$(27) + "[38;2;" + _trim$(str$(_red32(colorvalue))) + ";" + _trim$(str$(_green32(colorvalue))) + ";" + _trim$(str$(_blue32(colorvalue))) + "m"
|
termcolor = chr$(27) + "[38;2;" + _trim$(str$(_red32(colorvalue))) + ";" + _trim$(str$(_green32(colorvalue))) + ";" + _trim$(str$(_blue32(colorvalue))) + "m"
|
||||||
end select
|
end select
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function cursorback$ ()
|
function cursorback$ ()
|
||||||
cursorback = chr$(27) + "[F"
|
cursorback = chr$(27) + "[F"
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function clearline$
|
function clearline$
|
||||||
clearline = chr$(27) + "[2K"
|
clearline = chr$(27) + "[2K"
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function clearrest$
|
function clearrest$
|
||||||
clearrest = chr$(27) + "[K"
|
clearrest = chr$(27) + "[K"
|
||||||
end function
|
end function
|
||||||
|
|
||||||
sub cursoroff ()
|
sub cursoroff ()
|
||||||
print chr$(27); "[?25l";
|
print chr$(27); "[?25l";
|
||||||
end sub
|
end sub
|
||||||
|
|
||||||
sub cursoron ()
|
sub cursoron ()
|
||||||
print chr$(27); "[?25h";
|
print chr$(27); "[?25h";
|
||||||
end sub
|
end sub
|
||||||
|
|
||||||
function bar$ (length as integer, percent as integer, color1 as long, color2 as long)
|
function bar$ (length as integer, percent as integer, color1 as long, color2 as long)
|
||||||
dim done as string
|
dim done as string
|
||||||
dim notdone as string
|
dim notdone as string
|
||||||
dim i as integer
|
dim i as integer
|
||||||
for i = 1 to int((percent / 100) * length)
|
for i = 1 to int((percent / 100) * length)
|
||||||
done = done + "━"
|
done = done + "━"
|
||||||
next i
|
next i
|
||||||
for i = 1 to length - int((percent / 100) * length)
|
for i = 1 to length - int((percent / 100) * length)
|
||||||
notdone = notdone + "━"
|
notdone = notdone + "━"
|
||||||
next i
|
next i
|
||||||
bar$ = termcolor(color1) + done + termcolor(color2) + notdone
|
bar$ = termcolor(color1) + done + termcolor(color2) + notdone
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function afterlast$ (delim as string, strng as string)
|
function afterlast$ (delim as string, strng as string)
|
||||||
afterlast = mid$(strng, _instrrev(strng, delim) + 1)
|
afterlast = mid$(strng, _instrrev(strng, delim) + 1)
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function beforelast$ (delim as string, strng as string)
|
function beforelast$ (delim as string, strng as string)
|
||||||
beforelast = left$(strng, _instrrev(strng, delim) - 1)
|
beforelast = left$(strng, _instrrev(strng, delim) - 1)
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function AnimatedRainbowText$ (text$)
|
function AnimatedRainbowText$ (text$)
|
||||||
static offset as double
|
static offset as double
|
||||||
dim result as string
|
dim result as string
|
||||||
dim L as long, i as long
|
dim L as long, i as long
|
||||||
dim r as integer, g as integer, b as integer
|
dim r as integer, g as integer, b as integer
|
||||||
dim hue as double, f as double
|
dim hue as double, f as double
|
||||||
dim sector as integer, v as integer, p as integer, q as integer, t as integer
|
dim sector as integer, v as integer, p as integer, q as integer, t as integer
|
||||||
dim rgbPart$
|
dim rgbPart$
|
||||||
|
|
||||||
L = ulen(text$)
|
L = ulen(text$)
|
||||||
if L = 0 then exit function
|
if L = 0 then exit function
|
||||||
offset = offset + 5.0
|
offset = offset + 5.0
|
||||||
if offset >= 360 then offset = offset - 360
|
if offset >= 360 then offset = offset - 360
|
||||||
|
|
||||||
for i = 1 to L
|
for i = 1 to L
|
||||||
hue = MOD_Double(offset + ((i - 1) / L) * 360, 360)
|
hue = MOD_Double(offset + ((i - 1) / L) * 360, 360)
|
||||||
sector = int(hue / 60)
|
sector = int(hue / 60)
|
||||||
f = (hue / 60) - sector
|
f = (hue / 60) - sector
|
||||||
v = 255: p = 0: q = 255 * (1 - f): t = 255 * f
|
v = 255: p = 0: q = 255 * (1 - f): t = 255 * f
|
||||||
select case sector
|
select case sector
|
||||||
case 0: r = v: g = t: b = p
|
case 0: r = v: g = t: b = p
|
||||||
case 1: r = q: g = v: b = p
|
case 1: r = q: g = v: b = p
|
||||||
case 2: r = p: g = v: b = t
|
case 2: r = p: g = v: b = t
|
||||||
case 3: r = p: g = q: b = v
|
case 3: r = p: g = q: b = v
|
||||||
case 4: r = t: g = p: b = v
|
case 4: r = t: g = p: b = v
|
||||||
case 5: r = v: g = p: b = q
|
case 5: r = v: g = p: b = q
|
||||||
end select
|
end select
|
||||||
rgbPart$ = _trim$(str$(r)) + ";" + _trim$(str$(g)) + ";" + _trim$(str$(b))
|
rgbPart$ = _trim$(str$(r)) + ";" + _trim$(str$(g)) + ";" + _trim$(str$(b))
|
||||||
result = result + chr$(27) + "[38;2;" + rgbPart$ + "m" + umid$(text$, i, 1)
|
result = result + chr$(27) + "[38;2;" + rgbPart$ + "m" + umid$(text$, i, 1)
|
||||||
next i
|
next i
|
||||||
AnimatedRainbowText$ = result + chr$(27) + "[0m"
|
AnimatedRainbowText$ = result + chr$(27) + "[0m"
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function MOD_Double (value as double, m as double)
|
function MOD_Double (value as double, m as double)
|
||||||
MOD_Double = value - (m * int(value / m))
|
MOD_Double = value - (m * int(value / m))
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function ulen% (txt$)
|
function ulen% (txt$)
|
||||||
dim count%, i%, b%
|
dim count%, i%, b%
|
||||||
count% = 0
|
count% = 0
|
||||||
for i% = 1 to len(txt$)
|
for i% = 1 to len(txt$)
|
||||||
b% = asc(txt$, i%)
|
b% = asc(txt$, i%)
|
||||||
if (b% and &H80) = 0 or (b% and &HC0) = &HC0 then
|
if (b% and &H80) = 0 or (b% and &HC0) = &HC0 then
|
||||||
count% = count% + 1
|
count% = count% + 1
|
||||||
end if
|
end if
|
||||||
next
|
next
|
||||||
ulen% = count%
|
ulen% = count%
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function umid$ (txt$, startChar%, numChars%)
|
function umid$ (txt$, startChar%, numChars%)
|
||||||
if startChar% < 1 or numChars% <= 0 or txt$ = "" then exit function
|
if startChar% < 1 or numChars% <= 0 or txt$ = "" then exit function
|
||||||
|
|
||||||
dim byteIdx%, charCount%, startByte%, endByte%, b%
|
dim byteIdx%, charCount%, startByte%, endByte%, b%
|
||||||
byteIdx% = 1
|
byteIdx% = 1
|
||||||
charCount% = 0
|
charCount% = 0
|
||||||
|
|
||||||
while byteIdx% <= len(txt$)
|
while byteIdx% <= len(txt$)
|
||||||
b% = asc(txt$, byteIdx%)
|
b% = asc(txt$, byteIdx%)
|
||||||
if (b% and &H80) = 0 or (b% and &HC0) = &HC0 then
|
if (b% and &H80) = 0 or (b% and &HC0) = &HC0 then
|
||||||
charCount% = charCount% + 1
|
charCount% = charCount% + 1
|
||||||
if charCount% = startChar% then startByte% = byteIdx%
|
if charCount% = startChar% then startByte% = byteIdx%
|
||||||
end if
|
end if
|
||||||
if startByte% > 0 then exit while
|
if startByte% > 0 then exit while
|
||||||
byteIdx% = byteIdx% + 1
|
byteIdx% = byteIdx% + 1
|
||||||
wend
|
wend
|
||||||
|
|
||||||
if startByte% = 0 then exit function
|
if startByte% = 0 then exit function
|
||||||
|
|
||||||
byteIdx% = startByte%
|
byteIdx% = startByte%
|
||||||
dim charsFound%
|
dim charsFound%
|
||||||
charsFound% = 0
|
charsFound% = 0
|
||||||
|
|
||||||
while byteIdx% <= len(txt$)
|
while byteIdx% <= len(txt$)
|
||||||
b% = asc(txt$, byteIdx%)
|
b% = asc(txt$, byteIdx%)
|
||||||
if (b% and &H80) = 0 or (b% and &HC0) = &HC0 then
|
if (b% and &H80) = 0 or (b% and &HC0) = &HC0 then
|
||||||
charsFound% = charsFound% + 1
|
charsFound% = charsFound% + 1
|
||||||
end if
|
end if
|
||||||
if charsFound% > numChars% then exit while
|
if charsFound% > numChars% then exit while
|
||||||
byteIdx% = byteIdx% + 1
|
byteIdx% = byteIdx% + 1
|
||||||
wend
|
wend
|
||||||
|
|
||||||
umid$ = mid$(txt$, startByte%, byteIdx% - startByte%)
|
umid$ = mid$(txt$, startByte%, byteIdx% - startByte%)
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function UWidth% (txt$)
|
function UWidth% (txt$)
|
||||||
dim totalWidth%, i%, char$, cp&
|
dim totalWidth%, i%, char$, cp&
|
||||||
totalWidth% = 0
|
totalWidth% = 0
|
||||||
for i% = 1 to ulen(txt$)
|
for i% = 1 to ulen(txt$)
|
||||||
char$ = umid(txt$, i%, 1)
|
char$ = umid(txt$, i%, 1)
|
||||||
cp& = GetCodePoint&(char$)
|
cp& = GetCodePoint&(char$)
|
||||||
|
|
||||||
if cp& > &H1100 then
|
if cp& > &H1100 then
|
||||||
totalWidth% = totalWidth% + 2
|
totalWidth% = totalWidth% + 2
|
||||||
else
|
else
|
||||||
totalWidth% = totalWidth% + 1
|
totalWidth% = totalWidth% + 1
|
||||||
end if
|
end if
|
||||||
next
|
next
|
||||||
UWidth% = totalWidth%
|
UWidth% = totalWidth%
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function GetCodePoint& (utf8Char$)
|
function GetCodePoint& (utf8Char$)
|
||||||
dim lLength as integer
|
dim lLength as integer
|
||||||
lLength = len(utf8Char$)
|
lLength = len(utf8Char$)
|
||||||
dim b1 as _unsigned _byte, b2 as _unsigned _byte
|
dim b1 as _unsigned _byte, b2 as _unsigned _byte
|
||||||
dim b3 as _unsigned _byte, b4 as _unsigned _byte
|
dim b3 as _unsigned _byte, b4 as _unsigned _byte
|
||||||
|
|
||||||
select case lLength
|
select case lLength
|
||||||
case 1
|
case 1
|
||||||
GetCodePoint& = asc(utf8Char$, 1)
|
GetCodePoint& = asc(utf8Char$, 1)
|
||||||
case 2
|
case 2
|
||||||
b1 = asc(utf8Char$, 1): b2 = asc(utf8Char$, 2)
|
b1 = asc(utf8Char$, 1): b2 = asc(utf8Char$, 2)
|
||||||
GetCodePoint& = (b1 and &H1F) * 64 + (b2 and &H3F)
|
GetCodePoint& = (b1 and &H1F) * 64 + (b2 and &H3F)
|
||||||
case 3
|
case 3
|
||||||
b1 = asc(utf8Char$, 1): b2 = asc(utf8Char$, 2): b3 = asc(utf8Char$, 3)
|
b1 = asc(utf8Char$, 1): b2 = asc(utf8Char$, 2): b3 = asc(utf8Char$, 3)
|
||||||
GetCodePoint& = (b1 and &H0F) * 4096 + (b2 and &H3F) * 64 + (b3 and &H3F)
|
GetCodePoint& = (b1 and &H0F) * 4096 + (b2 and &H3F) * 64 + (b3 and &H3F)
|
||||||
case 4
|
case 4
|
||||||
b1 = asc(utf8Char$, 1): b2 = asc(utf8Char$, 2): b3 = asc(utf8Char$, 3): b4 = asc(utf8Char$, 4)
|
b1 = asc(utf8Char$, 1): b2 = asc(utf8Char$, 2): b3 = asc(utf8Char$, 3): b4 = asc(utf8Char$, 4)
|
||||||
GetCodePoint& = (b1 and &H07) * 262144 + (b2 and &H3F) * 4096 + (b3 and &H3F) * 64 + (b4 and &H3F)
|
GetCodePoint& = (b1 and &H07) * 262144 + (b2 and &H3F) * 4096 + (b3 and &H3F) * 64 + (b4 and &H3F)
|
||||||
end select
|
end select
|
||||||
end function
|
end function
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue