bah
This commit is contained in:
parent
765372aa6b
commit
8af3bc9649
1 changed files with 505 additions and 505 deletions
236
cimp.bas
236
cimp.bas
|
|
@ -1,19 +1,19 @@
|
||||||
'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
|
||||||
|
|
||||||
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
|
||||||
|
|
@ -32,7 +32,7 @@ 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
|
||||||
|
|
@ -46,17 +46,17 @@ 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
|
||||||
|
|
@ -64,7 +64,7 @@ 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)
|
||||||
|
|
@ -86,7 +86,7 @@ for i=1 to _commandcount
|
||||||
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)
|
||||||
|
|
@ -112,21 +112,21 @@ 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
|
||||||
|
|
@ -215,52 +215,52 @@ while keyin<>27
|
||||||
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
|
||||||
|
|
||||||
|
|
@ -286,12 +286,12 @@ sub shufflearray (stringarray() as string)
|
||||||
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
|
||||||
|
|
@ -302,12 +302,12 @@ sub parsem3u (filename$,array$())
|
||||||
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
|
||||||
|
|
@ -383,22 +383,22 @@ 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
|
||||||
|
|
@ -410,14 +410,14 @@ function animatedrainbowtext$ (text$)
|
||||||
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$)
|
||||||
|
|
@ -425,81 +425,81 @@ function ulen% (txt$)
|
||||||
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