jhass changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Crystal 0.35.1 | Fund Crystal's development: https://crystal-lang.org/sponsors | GH: https://github.com/crystal-lang/crystal | Docs: https://crystal-lang.org/docs | Gitter: https://gitter.im/crystal-lang/crystal
<raz> hm, can we shutdown crystalshards.org?
<raz> it seems to be perpetually broken, looks bad
<FromGitter> <Blacksmoke16> :shrug:
<FromGitter> <Blacksmoke16> Probably easier to fix it
<raz> yeh but if nobody maintains it, it only hurts our google juice
<raz> as a newcomer i'd prob go there first cause the name sounds official (before learning about the .xyz version)
<FromGitter> <ImAHopelessDev_gitlab> we should have an official shard site
<FromGitter> <ImAHopelessDev_gitlab> all the others should be useless, a waste of time
<raz> yeh, for me the xyz one is fine enough, could as well be made official
<FromGitter> <Blacksmoke16> There's also the one @straight-shoota made
<raz> yeh but that manual curation thing is a non-starter
<raz> i still don't understand why he built a yahoo in the age of google :p
f1reflyylmao has joined #crystal-lang
f1refly has quit [Ping timeout: 272 seconds]
avane has quit [Quit: ZNC - https://znc.in]
avane has joined #crystal-lang
_whitelogger has joined #crystal-lang
f1refly has joined #crystal-lang
f1reflyylmao has quit [Ping timeout: 240 seconds]
renich has quit [Ping timeout: 264 seconds]
_whitelogger has joined #crystal-lang
<oprypin> ^this
<FromGitter> <Souravgoswami> How do I get the script working directory?
<FromGitter> <Souravgoswami> For example, if my program is in /tmp, and I run the program from /home/sourav, I should get /tmp
<FromGitter> <Souravgoswami> ```Kernel.__dir__()``` ⏎ ⏎ in ruby [https://gitter.im/crystal-lang/crystal?at=5f93de49a0a3072b43a01e28]
<FromGitter> <grkek> *DIR*
<FromGitter> <grkek> ```__DIR__```
<FromGitter> <Souravgoswami> Oh thanks a lot for this!
<FromGitter> <Souravgoswami> While reading docs to find out the answer for above question, I noticed this: ⏎ ⏎ https://github.com/crystal-lang/crystal/blob/c2c2276ec667171af5c2347490f49acdbdc4a3ca/src/colorize.cr#L104
<FromGitter> <Souravgoswami> The problem is, it's not light red, it depends on the terminal
<FromGitter> <Souravgoswami> But \e[38;2;r;g;bm should print the desired colour
<FromGitter> <Souravgoswami> I am not compiling it though, I am running the program like a script once to test
<FromGitter> <grkek> Open an issue on the issue page :)
<FromGitter> <Souravgoswami> Umm is that worth it? Small stuffs 😂
<FromGitter> <grkek> Yes it is, since it is an issue and it made your terminal feel sad
<FromGitter> <Souravgoswami> Ok! Will do!
<FromGitter> <HertzDevil> yeah of course the 16-color palette depends on your terminal
<FromGitter> <HertzDevil> use `Colorize::ColorRGB` to construct the \e[38;2 sequence
<FromGitter> <Souravgoswami> Yup that will be cleaner... But there's a problem... But it won't work on TTY. In a project of mine, I used to check if it's a colour term or not: ⏎ ⏎ CLEAR = COLOURTERM ? "\e[3J\e[H\e[2J" : "\e[H" ⏎ ⏎ Then the clear sequence changes. Similarly we have to do that with crystal too... [https://gitter.im/crystal-lang/crystal?at=5f93e64f3d172d78b39553b7]
<FromGitter> <HertzDevil> that's a terminal problem not crystal's problem
<FromGitter> <Souravgoswami> Yup
issyl0 has quit [Ping timeout: 272 seconds]
<FromGitter> <HertzDevil> from what i see you have to do the same in ruby anyway
r0bby has quit [Ping timeout: 272 seconds]
r0bby has joined #crystal-lang
<FromGitter> <HertzDevil> you could do all of that in crystal, i doubt it would fit into the crystal standard library though
issyl0 has joined #crystal-lang
<FromGitter> <Souravgoswami> https://github.com/crystal-lang/crystal/issues/9845#issue-728738349 ⏎ ⏎ Even if we don't fix the colour sequence, that's fine, but we can add RGB and Hex conversions
<FromGitter> <HertzDevil> that requires crystal stdlib to assume a canonical rgb palette for the ansi colors
<oprypin> Souravgoswami, the real question is, why did you configure your terminal to have wrong colors
<FromGitter> <Souravgoswami> It can be. The light red can be dark red in other schemes. It's built into terminals. There are various schemes like Dark Pastel, Tango, Green on Black, Solarized light, Solarized dark, White on black, etc.
<oprypin> yea so what's the problem?
<FromGitter> <Souravgoswami> Not really an big issue TBH... Just saying
<oprypin> i dont want any tool to be able to use actual "light red"
<oprypin> then i couldnt see it on white
<oprypin> it is actually called "intense red". and i'll make a choice about it, thanks
<FromGitter> <Souravgoswami> Thank you, too!
zorp has joined #crystal-lang
zorp has quit [Remote host closed the connection]
zorp has joined #crystal-lang
zorp has quit [Ping timeout: 260 seconds]
<FromGitter> <j8r> How can I sort a Hash alphabetically?
<FromGitter> <j8r> I guess I have to use an intermediary Array?
<FromGitter> <Blacksmoke16> yes
<FromGitter> <Blacksmoke16> hash is sorted via insertion order, so would need to create a new hahs
<FromGitter> <j8r> I'll use `hash.keys.sort_by &.to_s`
<FromGitter> <Blacksmoke16> wouldnt you lose the reference to the value associated with each key tho?
<FromGitter> <j8r> hum yes oprypin, could be faster to use an array of tuple
<FromGitter> <j8r> I could have done `hash[key]` afterward
<FromGitter> <Blacksmoke16> thats what `.to_a` returns, then sorting it in place, then could use that to easy build a new hash via like https://crystal-lang.org/api/master/Enumerable.html#each_with_object(obj,&)-instance-method
<FromGitter> <Blacksmoke16> :shrug: more hash looks when you could have already have it
f1reflyylmao has joined #crystal-lang
f1refly has quit [Ping timeout: 260 seconds]
zorp has joined #crystal-lang
f1reflyylmao is now known as f1refly
Liothen has quit [Ping timeout: 260 seconds]
Liothen has joined #crystal-lang
<FromGitter> <grkek> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5f948949c990bb1c392c4314]
<FromGitter> <grkek> What happened here?
<FromGitter> <Blacksmoke16> *doom*
<FromGitter> <grkek> How the fuck do I fix that?
<FromGitter> <grkek> It works locally
<FromGitter> <Blacksmoke16> gl
<yxhuvud> @grkek: You got a segfault. I suggest you read through https://en.wikipedia.org/wiki/Segmentation_fault . Perhaps that can give you some idea of what your issue is.
<FromGitter> <grkek> It was because of the -Dpreview_mt
<FromGitter> <grkek> flag
<FromGitter> <grkek> fuck that I am not going to use it anymore
<FromGitter> <grkek> I know what a segfault is
<FromGitter> <Blacksmoke16> Libxml isn't thread safe
<FromGitter> <Blacksmoke16> There's an issue about it iirc
<FromGitter> <j8r> @Blacksmoke16 fuu, finally updated Clicr
<FromGitter> <j8r> so, can be removed from your PR - and added a monthly cron now
<FromGitter> <j8r> I'm glad to have achieved declarative CLI without all this macros hell: https://github.com/j8r/clicr. ⏎ There are little quirks, notably for the action method or composing options/commands, but overall it's worth it
<FromGitter> <j8r> really too bad we can't have named arguments for procs :(
<FromGitter> <Blacksmoke16> <3 thanks, will do
<FromGitter> <j8r> Not sure if having casting is a good idea...
<FromGitter> <Blacksmoke16> hm?
avane has quit [Quit: ZNC - https://znc.in]
avane has joined #crystal-lang
repo has quit [Quit: WeeChat 2.9]
<FromGitter> <j8r> I think it can be a good idea
<FromGitter> <Blacksmoke16> in what regard?
<FromGitter> <j8r> for example, showing the type when `--help`, like `--port Int32`
<FromGitter> <Blacksmoke16> yea would be handy for it to do that
<FromGitter> <Blacksmoke16> also allowing more advanced parsers would be nice, like to return more advanced types
<FromGitter> <j8r> the types would be very limited; though
<FromGitter> <j8r> I think all this validation should be done afterwards, not by the CLI
<FromGitter> <j8r> casting to Int/Float is simple, as `Int32.new` (or `.new?`, https://github.com/crystal-lang/crystal/pull/9389)
<raz> j8r: 'info' is bad. call it 'label' or 'description'
<FromGitter> <Blacksmoke16> i mean like how do you define the args/types?
<raz> other than that: <3
<FromGitter> <j8r> raz: there is already description, so that the short one
<raz> oh
<FromGitter> <Blacksmoke16> summary ^
<FromGitter> <j8r> yeah, or label looks ok too :)
<raz> i'd vote for label, but... i'm a nitpicker :P
<raz> it doesn't cast to types tho, or do i just not see it?
* raz scratches head
<raz> like, if i want an integer arg
<FromGitter> <j8r> Going to add that, for basic types
<FromGitter> <Blacksmoke16> make it so you have to provide the type of the arg
<FromGitter> <j8r> It will be trivial
<FromGitter> <Blacksmoke16> make it be based on an interface to allow custom type parsing
<FromGitter> <j8r> not sure what advantage it provides doing that?
<FromGitter> <j8r> Even if the user has `--database Database` in the `--help`, it won't have much information
<FromGitter> <Blacksmoke16> would allow taking a string file path and returning a `File` instance
<FromGitter> <Blacksmoke16> for use within the program
<FromGitter> <Blacksmoke16> https://github.com/Kotlin/kotlinx-cli/blob/master/core/commonMain/src/ArgType.kt we used this lib at work the other day and it was a handy feature
<FromGitter> <j8r> that's a bad idea for File, because of never closing FD
<FromGitter> <Blacksmoke16> cleaned up the actual code as we were able to have that logic be handled by the cli parser and not our code specifically
<FromGitter> <Blacksmoke16> sure, but you get the idea
<FromGitter> <j8r> I mean, what's much difference between having to do `MyCustomType.new string`?
<FromGitter> <j8r> inside the method?
<raz> for me it'd be nice if i could write { cast: to_i32, validate: Proc.new { |v| v > 0 && v < 42 } }
<raz> or something to that tune
<FromGitter> <Blacksmoke16> makes things easier to test/reuse? :shrug:
<FromGitter> <j8r> for now, will add primitives, like this ones: https://github.com/jwaldrip/admiral.cr#built-in-argument-types
<raz> or just { cast: Proc.new { ... } } where the proc can raise "OmgValidationError"
<FromGitter> <j8r> I think I have even nothing to do to support this feature :)
<raz> those are the best features
<FromGitter> <j8r> I have to think a bit more
<raz> accidental features :D
<FromGitter> <Blacksmoke16> also TIL http://docopt.org/ is a thing
<FromGitter> <j8r> interesting
<FromGitter> <j8r> not fan of their usage section (in the --help), though
<FromGitter> <Blacksmoke16> apparently thats what symfony CLI component is based on
<FromGitter> <Blacksmoke16> i dont mind it, shows all possible commands and what args they take etc
<raz> wow yea that looks cool
<FromGitter> <Blacksmoke16> also says it *can* have multiple patterns, idt its required
<raz> that screen would get a little crazy tho if you have many sub-commands / combinations
<raz> then again... any CLI impl gets crazy when you have many of those
<FromGitter> <Blacksmoke16> i imagine its more for an example to show combinations of things
<raz> probably a puzzle game to find the right combo to get what you actually want
<FromGitter> <Blacksmoke16> i have plans to add a console component to Athena, *not* to be used to make CLI applications, but moreso for creating an internal CLI API for your applicaiton
<FromGitter> <j8r> I prefer having a COMMANDS section
<FromGitter> <Blacksmoke16> https://github.com/docopt someone should make a Crystal one :S
<FromGitter> <j8r> à la docker, even busybox has a single-line Usage (or few lines)
<raz> mine has that t.ly/u8mx
<raz> but i'm too lazy to port that to crystal
<FromGitter> <Blacksmoke16> oh wait, hold up
<FromGitter> <Blacksmoke16> its used to generate the parser based on the docs
<FromGitter> <Blacksmoke16> not generate the docs based on the parser
<FromGitter> <Blacksmoke16> > docopt parses command-line arguments based on a help message. Don't write parser code: a good help message already has all the necessary information in it.
<raz> yup, the idea is awesome
<raz> i just wonder how well it works
<raz> but given how many impls it has, some people seem to like it
<FromGitter> <Blacksmoke16> and prob on the specific lang's implementation
<raz> yup
<raz> someone should make one for crystal to see how it goes :p
<FromGitter> <j8r> dunno, I don't imagine a huge cli like Docker using this
<FromGitter> <Blacksmoke16> i mean prob not, but seems pretty slick for just getting something working quickly
<FromGitter> <Blacksmoke16> depending on the complexity if it
<raz> i could see it being useful *especially* for go-lang
<raz> i don't even wanna know how much boilerplate their cli code has
<raz> they could probably trim >10k lines if they used docopt
<FromGitter> <j8r> it is this ergnomic to write a help string?
<FromGitter> <j8r> this means to indent and sort manually?
<raz> well, i could imagine it being more ergonomic than https://github.com/docker/cli/tree/master/cli/command
<raz> but... i haven't tried :D
<FromGitter> <Blacksmoke16> now we need to abstract generating the docopt string :S
<FromGitter> <j8r> I'd prefer writing a yaml, and then generate parser + help message
<raz> just wait for GPT-4
<FromGitter> <j8r> lol, yaml that generates the Help :P
<FromGitter> <j8r> *generated to
<FromGitter> <Blacksmoke16> prob wouldnt be too hard tbh
<FromGitter> <Blacksmoke16> some structs with a `to_s` method
<FromGitter> <j8r> at the end, we won't have something too far from Clicr...
<FromGitter> <j8r> the Crystal NamedTuple is close to JSON
repo1 has joined #crystal-lang