Skip to content

Commit abda751

Browse files
authored
Live reload yaml (#24)
1 parent 5e043b1 commit abda751

File tree

14 files changed

+226
-452
lines changed

14 files changed

+226
-452
lines changed

.scalafmt.conf

+6-240
Original file line numberDiff line numberDiff line change
@@ -1,243 +1,9 @@
1-
version = "3.7.14"
1+
version = "3.8.4"
22
maxColumn = 80
3-
docstrings.oneline = unfold
4-
docstrings.removeEmpty = false
5-
docstrings.wrap = yes
6-
docstrings.wrapMaxColumn = null
7-
docstrings.forceBlankLineBefore = null
8-
docstrings.blankFirstLine = no
9-
docstrings.style = SpaceAsterisk
10-
comments.wrap = no
11-
comments.wrapSingleLineMlcAsSlc = false
12-
comments.wrapStandaloneSlcAsSlc = false
13-
optIn.configStyleArguments = true
14-
optIn.breaksInsideChains = false
15-
optIn.breakChainOnFirstMethodDot = true
16-
optIn.encloseClassicChains = false
17-
optIn.selfAnnotationNewline = true
18-
optIn.annotationNewlines = true
19-
optIn.forceBlankLineBeforeDocstring = true
20-
binPack.unsafeCallSite = Never
21-
binPack.unsafeDefnSite = Never
22-
binPack.bracketCallSite = null
23-
binPack.bracketDefnSite = null
24-
binPack.indentCallSiteOnce = false
25-
binPack.indentCallSiteSingleArg = true
26-
binPack.parentConstructors = source
27-
binPack.literalArgumentLists = true
28-
binPack.literalsIncludeSimpleExpr = false
29-
binPack.literalsSingleLine = false
30-
binPack.literalsMinArgCount = 5
31-
binPack.literalsInclude = [
32-
".*"
33-
]
34-
binPack.literalsExclude = [
35-
String
36-
"Term.Name"
37-
]
38-
indent.main = 2
39-
indent.significant = null
40-
indent.callSite = 2
41-
indent.ctrlSite = null
3+
encoding = "UTF-8"
4+
runner.dialect = scala3
425
indent.defnSite = 2
43-
indent.caseSite = 2
44-
indent.matchSite = null
45-
indent.ctorSite = null
46-
indent.extraBeforeOpenParenDefnSite = 0
47-
indent.relativeToLhsLastLine = []
48-
indent.fewerBraces = never
496
indent.extendSite = 2
50-
indent.withSiteRelativeToExtends = 0
51-
indent.commaSiteRelativeToExtends = 2
52-
align.allowOverflow = false
53-
align.delayUntilSpace = true
54-
align.multiline = false
55-
align.stripMargin = true
56-
align.closeParenSite = false
57-
align.openBracketCallSite = null
58-
align.openParenCallSite = false
59-
align.openParenCtrlSite = false
60-
align.openBracketDefnSite = null
61-
align.openParenDefnSite = false
62-
align.openParenTupleSite = null
63-
align.beforeOpenParenDefnSite = false
64-
align.beforeOpenParenCallSite = false
65-
align.inInterpolation = false
66-
align.tokens = [
67-
{
68-
code = "=>"
69-
owner = Case
70-
owners = []
71-
}
72-
]
73-
align.arrowEnumeratorGenerator = false
74-
align.treeCategory."Defn.Trait" = "class/object/trait/enum"
75-
align.treeCategory."Defn.Object" = "class/object/trait/enum"
76-
align.treeCategory."Defn.Val" = "given/val/var/def"
77-
align.treeCategory."Defn.Enum" = "class/object/trait/enum"
78-
align.treeCategory."Defn.Macro" = "given/val/var/def"
79-
align.treeCategory."Decl.Def" = "given/val/var/def"
80-
align.treeCategory."Defn.Def" = "given/val/var/def"
81-
align.treeCategory."Defn.GivenAlias" = "given/val/var/def"
82-
align.treeCategory."Defn.Var" = "given/val/var/def"
83-
align.treeCategory."Enumerator.Generator" = for
84-
align.treeCategory."Enumerator.Val" = for
85-
align.treeCategory."Defn.Class" = "class/object/trait/enum"
86-
spaces.beforeContextBoundColon = Never
87-
spaces.beforeApplyArgInParens = Never
88-
spaces.beforeInfixArgInParens = Always
89-
spaces.afterTripleEquals = false
90-
spaces.inImportCurlyBraces = false
91-
spaces.inInterpolatedStringCurlyBraces = false
92-
spaces.inParentheses = false
93-
spaces.neverAroundInfixTypes = []
94-
spaces.afterKeywordBeforeParen = true
95-
spaces.inByNameTypes = true
96-
spaces.afterSymbolicDefs = false
97-
literals.long = Upper
98-
literals.float = Lower
99-
literals.double = Lower
100-
literals.hexDigits = Lower
101-
literals.hexPrefix = Lower
102-
literals.scientific = Lower
103-
lineEndings = unix
104-
rewrite.rules = []
105-
rewrite.scala3.convertToNewSyntax = false
106-
rewrite.scala3.removeOptionalBraces = no
107-
rewrite.scala3.countEndMarkerLines = all
108-
rewrite.scala3.removeEndMarkerMaxLines = 0
109-
rewrite.scala3.insertEndMarkerMinLines = 0
110-
rewrite.insertBraces.minLines = 0
111-
rewrite.insertBraces.allBlocks = false
112-
rewrite.redundantBraces.defnBodies = all
113-
rewrite.redundantBraces.includeUnitMethods = true
114-
rewrite.redundantBraces.maxBreaks = 100
115-
rewrite.redundantBraces.stringInterpolation = false
116-
rewrite.redundantBraces.parensForOneLineApply = true
117-
rewrite.redundantBraces.generalExpressions = true
118-
rewrite.redundantBraces.ifElseExpressions = false
119-
rewrite.redundantParens.infixSide = null
120-
rewrite.sortModifiers.order = [
121-
implicit
122-
final
123-
sealed
124-
abstract
125-
override
126-
private
127-
protected
128-
lazy
129-
open
130-
transparent
131-
inline
132-
infix
133-
opaque
134-
]
135-
rewrite.imports.sort = none
136-
rewrite.imports.expand = false
137-
rewrite.imports.contiguousGroups = only
138-
rewrite.imports.groups = []
139-
rewrite.preferCurlyFors.removeTrailingSemicolonsOnly = false
140-
rewrite.trailingCommas.allowFolding = true
141-
rewrite.trailingCommas.style = never
142-
rewrite.allowInfixPlaceholderArg = true
143-
rewrite.neverInfix.excludeFilters = [
144-
until
145-
to
146-
by
147-
eq
148-
ne
149-
"should.*"
150-
"contain.*"
151-
"must.*"
152-
in
153-
ignore
154-
be
155-
taggedAs
156-
thrownBy
157-
synchronized
158-
have
159-
when
160-
size
161-
only
162-
noneOf
163-
oneElementOf
164-
noElementsOf
165-
atLeastOneElementOf
166-
atMostOneElementOf
167-
allElementsOf
168-
inOrderElementsOf
169-
theSameElementsAs
170-
]
171-
indentOperator.exemptScope = null
172-
indentOperator.topLevelOnly = true
173-
indentOperator.includeRegex = ".*"
174-
newlines.avoidInResultType = false
175-
newlines.neverBeforeJsNative = false
176-
newlines.sometimesBeforeColonInMethodReturnType = true
177-
newlines.penalizeSingleSelectMultiArgList = true
178-
newlines.beforeCurlyLambdaParams = never
179-
newlines.topLevelStatementBlankLines = []
180-
newlines.topLevelStatementsMinBreaks = 1
181-
newlines.topLevelStatements = []
182-
newlines.beforeTemplateBodyIfBreakInParentCtors = false
183-
newlines.topLevelBodyIfMinStatements = []
184-
newlines.topLevelBodyMinStatements = 2
185-
newlines.afterCurlyLambdaParams = never
186-
newlines.implicitParamListModifierForce = []
187-
newlines.alwaysBeforeElseAfterCurlyIf = false
188-
newlines.forceBeforeAssign = never
189-
newlines.alwaysBeforeMultilineDef = false
190-
newlines.afterInfixBreakOnNested = false
191-
newlines.afterInfixMaxCountPerExprForSome = 10
192-
newlines.afterInfixMaxCountPerFile = 500
193-
newlines.avoidForSimpleOverflow = []
194-
newlines.inInterpolation = allow
195-
newlines.ignoreInSyntax = true
196-
newlines.avoidAfterYield = true
197-
runner.debug = false
198-
runner.eventCallback = "<FormatEvent => Unit>"
199-
runner.parser = Source
200-
runner.optimizer.dequeueOnNewStatements = true
201-
runner.optimizer.escapeInPathologicalCases = true
202-
runner.optimizer.maxVisitsPerToken = 10000
203-
runner.optimizer.maxEscapes = 16
204-
runner.optimizer.maxDepth = 100
205-
runner.optimizer.acceptOptimalAtHints = true
206-
runner.optimizer.disableOptimizationsInsideSensitiveAreas = true
207-
runner.optimizer.pruneSlowStates = true
208-
runner.optimizer.recurseOnBlocks = true
209-
runner.optimizer.forceConfigStyleOnOffset = 150
210-
runner.optimizer.forceConfigStyleMinArgCount = 2
211-
runner.maxStateVisits = 1000000
212-
runner.dialect = scala3
213-
runner.ignoreWarnings = false
214-
runner.fatalWarnings = false
215-
indentYieldKeyword = true
216-
importSelectors = noBinPack
217-
includeCurlyBraceInSelectChains = true
218-
includeNoParensInSelectChains = false
219-
assumeStandardLibraryStripMargin = false
220-
danglingParentheses.callSite = true
221-
danglingParentheses.defnSite = true
222-
danglingParentheses.ctrlSite = true
223-
danglingParentheses.tupleSite = null
224-
danglingParentheses.exclude = null
225-
poorMansTrailingCommasInConfigStyle = false
226-
trailingCommas = null
227-
verticalMultiline.atDefnSite = false
228-
verticalMultiline.arityThreshold = 100
229-
verticalMultiline.newlineAfterOpenParen = false
230-
verticalAlignMultilineOperators = false
231-
onTestFailure = ""
232-
encoding = "UTF-8"
233-
project.git = false
234-
project.layout = null
235-
project.includePaths = [
236-
"glob:**.scala"
237-
"glob:**.sbt"
238-
"glob:**.sc"
239-
]
240-
project.excludePaths = []
241-
project.includeFilters = []
242-
project.excludeFilters = []
243-
xmlLiterals.assumeFormatted = false
7+
rewrite.rules = [Imports, RedundantBraces]
8+
rewrite.imports.expand = true
9+
rewrite.imports.sort = original

frontend-laminar/src/main/scala/ru/d10xa/jsonlogviewer/ViewElement.scala

+21-22
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
package ru.d10xa.jsonlogviewer
22

3-
import cats.effect.IO
43
import cats.effect.unsafe.implicits.global
4+
import cats.effect.IO
5+
import cats.effect.Ref
56
import com.monovore.decline.Help
67
import com.raquo.airstream.core.Signal
78
import com.raquo.airstream.eventbus.EventBus
89
import com.raquo.airstream.ownership.Owner
9-
import com.raquo.laminar.DomApi
1010
import com.raquo.laminar.api.L.*
11-
import ru.d10xa.jsonlogviewer.decline.Config
11+
import com.raquo.laminar.DomApi
1212
import ru.d10xa.jsonlogviewer.decline.yaml.ConfigYaml
1313
import ru.d10xa.jsonlogviewer.decline.yaml.Feed
14+
import ru.d10xa.jsonlogviewer.decline.Config
1415

1516
import scala.util.chaining.*
1617

@@ -23,23 +24,16 @@ object ViewElement {
2324
.pipe(DomApi.unsafeParseHtmlString)
2425
.pipe(foreignHtmlElement)
2526

26-
def modifyConfigForInlineInput(string: String, config: Config): Config =
27-
config.copy(configYaml =
28-
Some(
29-
ConfigYaml(
30-
filter = None,
31-
formatIn = None,
32-
commands = None,
33-
feeds = Some(
34-
List(
35-
Feed(
36-
name = None,
37-
commands = List.empty,
38-
inlineInput = Some(string),
39-
filter = config.filter,
40-
formatIn = config.formatIn
41-
)
42-
)
27+
def makeConfigYamlForInlineInput(string: String, config: Config): ConfigYaml =
28+
ConfigYaml(
29+
feeds = Some(
30+
List(
31+
Feed(
32+
name = None,
33+
commands = List.empty,
34+
inlineInput = Some(string),
35+
filter = config.filter,
36+
formatIn = config.formatIn
4337
)
4438
)
4539
)
@@ -54,8 +48,13 @@ object ViewElement {
5448
.combineWith(configSignal)
5549
.foreach {
5650
case (string, Right(c)) =>
57-
LogViewerStream
58-
.stream(modifyConfigForInlineInput(string, c))
51+
val configYamlRefIO =
52+
Ref.of[IO, Option[ConfigYaml]](
53+
Some(makeConfigYamlForInlineInput(string, c))
54+
)
55+
fs2.Stream
56+
.eval(configYamlRefIO)
57+
.flatMap(configYamlRef => LogViewerStream.stream(c, configYamlRef))
5958
.compile
6059
.toList
6160
.map(stringsToHtmlElement)
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
package ru.d10xa.jsonlogviewer.decline
22

3+
import cats.effect.std.Supervisor
34
import cats.effect.IO
5+
import cats.effect.Ref
6+
import cats.effect.Resource
7+
import ru.d10xa.jsonlogviewer.decline.yaml.ConfigYaml
48
import ru.d10xa.jsonlogviewer.decline.Config.FormatIn
59

610
class ConfigInitImpl extends ConfigInit {
711

8-
override def initConfig(c: Config): IO[Config] = {
9-
IO.pure(
10-
c.copy(
11-
formatIn = c.formatIn.orElse(Some(FormatIn.Json)),
12-
filter = c.filter
13-
)
14-
)
15-
}
12+
override def initConfigYaml(
13+
c: Config,
14+
supervisor: Supervisor[IO]
15+
): Resource[IO, Ref[IO, Option[ConfigYaml]]] =
16+
Resource.eval(Ref.of(None))
1617
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package ru.d10xa.jsonlogviewer
22

33
import cats.effect.*
4-
import com.monovore.decline.Opts
4+
import cats.effect.std.Supervisor
55
import com.monovore.decline.effect.CommandIOApp
6+
import com.monovore.decline.Opts
67
import fs2.*
78
import ru.d10xa.jsonlogviewer.decline.ConfigInit
89
import ru.d10xa.jsonlogviewer.decline.ConfigInitImpl
@@ -16,16 +17,18 @@ object Application
1617

1718
private val configInit: ConfigInit = new ConfigInitImpl
1819

19-
def main: Opts[IO[ExitCode]] = DeclineOpts.config.map { c =>
20-
configInit.initConfig(c).flatMap { updatedConfig =>
21-
IO {
20+
def main: Opts[IO[ExitCode]] = DeclineOpts.config.map { config =>
21+
Supervisor[IO].use { supervisor =>
22+
configInit.initConfigYaml(config, supervisor).use { configRef =>
2223
LogViewerStream
23-
.stream(updatedConfig)
24+
.stream(config, configRef)
2425
.through(text.utf8.encode)
25-
.through(io.stdout)
26+
.through(fs2.io.stdout)
2627
.compile
2728
.drain
2829
.as(ExitCode.Success)
29-
}.flatten
30+
}
3031
}
32+
33+
3134
}

0 commit comments

Comments
 (0)