*[clean-code] push bycopy as pragma instead of individually.

*made notifyPlayerState a proc beacuse template just adds
duplicate code

 - [1] code look clean.
 - [2] obvious.
This commit is contained in:
Anton 2024-04-10 09:13:49 +01:00
parent 081d8baa26
commit 7f35330d6b
5 changed files with 33 additions and 25 deletions

View file

@ -259,59 +259,62 @@ type #enums
llDebug = 60, ##more noisy verbose info
llTrace = 70 ##extermely verbose
{.push bycopy.}
type
#non-enum type objects
Handle* = distinct pointer ##(private) basic type, used by api to
##infer the context
ClientUnionType* {.bycopy, union.} = object
ClientUnionType* {.union.} = object
str*: cstring
flag*, int*: cint
double*: cdouble
list*: ptr NodeList
ba*: ptr ByteArray
Node* {.bycopy.} = object
Node* = object
u*: ClientUnionType
format*: Format
NodeList* {.bycopy.} = object
NodeList* = object
num*: cint
values*: ptr Node
keys*: cstringArray
ByteArray* {.bycopy.} = object
ByteArray* = object
data*: pointer
size*: csize_t
EventProperty* {.bycopy.} = object
EventProperty* = object
name*: cstring
format*: Format
data*: pointer
EventLogMessage* {.bycopy.} = object
EventLogMessage* = object
prefix*, level*, text*: cstring
logLevel*: LogLevel
EventEndFile* {.bycopy.} = object
EventEndFile* = object
reason*, error*: cint
EventClientMessage* {.bycopy.} = object
EventClientMessage* = object
numArgs*: cint
args*: cstringArray
EventHook* {.bycopy.} = object
EventHook* = object
name*: cstring
id*: cint
EventCmd* {.bycopy.} = object
EventCmd* = object
result*: Node
Event* {.bycopy.} = object
Event* = object
eventID*: EventID
error*: int
replyUserData*: uint64
data*: pointer
{.pop.}
#procs
using
ctx: ptr Handle
@ -482,4 +485,6 @@ proc checkError*(status: cint) = ##[
showCursor()
raise newException(CatchableError, "mpv API error: " & $errorString status)
template cE*(s: int) = checkError s
{.pop.}

View file

@ -23,7 +23,7 @@ proc doesLinkWork*(link: string): bool =
#for link with no port will except
else: parseInt seq[1]),
timeout = 2000)
echo "link dont cause except"
# echo "link dont cause except"
return true
except HttpRequestError: warn "HttpRequestError. bad link?"
except IndexDefect: return true #lmpv will error IDEndFile if badLink

View file

@ -14,7 +14,7 @@ template endThisCall(str: string) =
terminateDestroy ctx
break
template notifyplayerState =
proc notifyplayerState(isPaused, isMuted: bool) =
cursorDown()
eraseLine()
if not isPaused:
@ -53,6 +53,8 @@ proc call(sub: string; sect = ""; stat, link: string) =
try: illwillinit false
except IllWillError: discard
cursorDown()
say "Playing", fgGreen
cursorDown()
#echo "link in call() before while true: " & link
@ -82,47 +84,45 @@ proc call(sub: string; sect = ""; stat, link: string) =
if isPaused:
isPaused = false
ctx.pause false
notifyPlayerState()
notifyPlayerState(isPaused, isMuted)
else:
ctx.pause true
isPaused = true
notifyPlayerState()
notifyPlayerState(isPaused, isMuted)
of Key.M:
if isMuted:
ctx.mute false
isMuted = false
notifyPlayerState()
notifyPlayerState(isPaused, isMuted)
else:
ctx.mute true
isMuted = true
notifyPlayerState()
notifyPlayerState(isPaused, isMuted)
of Key.Slash, Key.Plus:
let volumeIncreased = ctx.volume true
#[var metadata: NodeList
echo "getPropreturnVal:", ctx.getProperty("metadata", fmtNodeMap, addr metadata)
echo "metadata", metadata.num
for i in 0 .. 100:
try:echo "metadatavalues", metadata.values[i]
except:discard]#
cursorDown()
cursorDown()
warn "Volume+: " & $volumeIncreased
cursorUp()
eraseLine()
cursorUp()
cursorUp()
of Key.Asterisk, Key.Minus:
let volumeDecreased = ctx.volume false
cursorDown()
cursorDown()
warn "Volume-: " & $volumeDecreased
cursorUp()
eraseLine()
cursorUp()
cursorUp()
of Key.R:
if not isPaused: terminateDestroy ctx

View file

@ -1,7 +1,5 @@
import client
template cE*(s: cint) = checkError s
using
ctx: ptr Handle
@ -36,3 +34,5 @@ proc seeIfCoreIsIdling*(ctx): cint =
proc getCurrentSongv2*(ctx): cstring =
cE ctx.getProperty("media-title", fmtString, addr result)
export cE

View file

@ -94,11 +94,14 @@ proc warn*(txt: string; x = 4; colour = fgRed) =
sleep 750
proc inv* =
cursorDown()
cursorDown()
warn "INVALID CHOICE"
cursorUp()
eraseLine()
cursorUp()
cursorUp()
template sayTermDraw8*() =
say "Poor Mans Radio Player in Nim-lang " &