Skip to content

Commit c58b8d4

Browse files
committed
refactor: added getters and setters to Color object
FossilOrigin-Name: 2485a929925f945f43d395f5d0c807485e33cab5f5256c72485c4e815e533455
1 parent 878b07b commit c58b8d4

File tree

1 file changed

+37
-6
lines changed

1 file changed

+37
-6
lines changed

src/theme.nim

+37-6
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type
4646
helpCode, highlightValid, highlightInvalid, highlightVariable,
4747
highlightText, suggestInvalid, suggestCommand, suggestYes, suggestNext,
4848
suggestAbort, promptColor, promptError, completionList
49+
ColorDescription = string
4950
Color* {.tableName: "theme".} = ref object of Model
5051
## Data structure for the shell's color
5152
##
@@ -55,12 +56,12 @@ type
5556
## * bold - if true, set the color with a bold font
5657
## * underline - if true, add underline to the color
5758
## * italic - if true, set the color with an italic font
58-
name* {.unique.}: ThemeColor
59-
cValue*: ColorName
60-
description*: string
61-
bold*: bool
62-
underline*: bool
63-
italic*: bool
59+
name {.unique.}: ThemeColor
60+
cValue: ColorName
61+
description: ColorDescription
62+
bold: bool
63+
underline: bool
64+
italic: bool
6465
ColorCode* = string
6566
## Used to get the terminal code for a color
6667

@@ -69,6 +70,36 @@ using db: DbConn # Connection to the shell's database
6970
const themeCommands*: seq[string] = @["list", "edit", "reset"]
7071
## The list of available subcommands for command theme
7172

73+
template colorGetterSetter(name: untyped; typ: typedesc) =
74+
## Set the getter for a field of Color type
75+
##
76+
## * name - the name of the field for which the getter will be set
77+
## * typ - the type of the value of the field
78+
proc `name`*(col: Color): `typ` {.sideEffect, raises: [], tags: [],
79+
contractual.} =
80+
## The getter of a field of Color type
81+
##
82+
## * col - the shell's color
83+
##
84+
## Returns the value of the selected field
85+
col.`name`
86+
proc `name=`*(col: var Color; value: `typ`) {.sideEffect, raises: [],
87+
tags: [], contractual.} =
88+
## The setter of a field of Color type
89+
##
90+
## * col - the shell's color
91+
## * value - the new value for the selected field
92+
##
93+
## Returns modified field of the color
94+
col.`name` = value
95+
96+
colorGetterSetter(name = name, typ = ThemeColor)
97+
colorGetterSetter(name = cValue, typ = ColorName)
98+
colorGetterSetter(name = description, typ = ColorDescription)
99+
colorGetterSetter(name = bold, typ = bool)
100+
colorGetterSetter(name = underline, typ = bool)
101+
colorGetterSetter(name = italic, typ = bool)
102+
72103
proc dbType(T: typedesc[ColorName]): string {.raises: [], tags: [],
73104
contractual.} =
74105
## Set the type of field in the database

0 commit comments

Comments
 (0)