Mercurial > games > semicongine
comparison semiconginev2/old/core/utils.nim @ 1227:4d97cfc4888b
merge
| author | sam <sam@basx.dev> |
|---|---|
| date | Wed, 17 Jul 2024 23:45:43 +0700 |
| parents | 56781cc0fc7c |
| children |
comparison
equal
deleted
inserted
replaced
| 1170:2addc5f6804f | 1227:4d97cfc4888b |
|---|---|
| 1 import std/typetraits | |
| 2 import std/strutils | |
| 3 import std/paths | |
| 4 import std/os | |
| 5 import std/strformat | |
| 6 | |
| 7 type | |
| 8 HorizontalAlignment* = enum | |
| 9 Left | |
| 10 Center | |
| 11 Right | |
| 12 VerticalAlignment* = enum | |
| 13 Top | |
| 14 Center | |
| 15 Bottom | |
| 16 | |
| 17 func CleanString*(str: openArray[char]): string = | |
| 18 for i in 0 ..< len(str): | |
| 19 if str[i] == char(0): | |
| 20 result = join(str[0 ..< i]) | |
| 21 break | |
| 22 | |
| 23 func ToCPointer*[T](list: openArray[T]): ptr T = | |
| 24 if list.len > 0: addr(list[0]) else: nil | |
| 25 | |
| 26 proc StaticExecChecked*(command: string, input = ""): string {.compileTime.} = | |
| 27 let (output, exitcode) = gorgeEx( | |
| 28 command = command, | |
| 29 input = input) | |
| 30 if exitcode != 0: | |
| 31 raise newException(Exception, &"Running '{command}' produced exit code: {exitcode}" & output) | |
| 32 return output | |
| 33 | |
| 34 proc AppName*(): string = | |
| 35 return string(Path(getAppFilename()).splitFile.name) | |
| 36 | |
| 37 func Size*[T: seq](list: T): uint64 = | |
| 38 uint64(list.len * sizeof(get(genericParams(typeof(list)), 0))) |
