ChanServ changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | 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
<FromGitter> <Blacksmoke16> is there a built in way to print a string with a max length of n?
<FromGitter> <tenebrousedge> how do you mean?
<FromGitter> <Blacksmoke16> ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=608214a2dc24646812da8123]
<FromGitter> <Blacksmoke16> assuming the width is 15
<FromGitter> <Blacksmoke16> looked like https://crystal-lang.org/api/master/PrettyPrint.html#format(obj,io:IO,width:Int32,newline=%22%5Cn%22,indent=0)-class-method could do it but doesnt seem to do the breaking, or at least doesnt consider the string breakable
<FromGitter> <tenebrousedge> I can't interpret the docs there
<FromGitter> <Blacksmoke16> guess ill just do it myself then
<FromGitter> <Blacksmoke16> open to better ideas tho :P
<FromGitter> <tenebrousedge> I mean you could get most of the way there with `gsub` but it would be nasty to read
<FromGitter> <tenebrousedge> oh um `each_cons`
<FromGitter> <Blacksmoke16> its also unfortunate colorize uses `0` code to end its sequences
<FromGitter> <Blacksmoke16> ```foo = "foo".colorize.red ⏎ ⏎ str = "hello #{foo} bar".colorize.underline ⏎ ⏎ puts str``` [https://gitter.im/crystal-lang/crystal?at=60821981b6a4714a29dfaaa6]
<FromGitter> <Blacksmoke16> `hello ` is underlined and white, `foo` is underlined and red, ` bar` is white but no underline because `0` code clears all versus just the red color :/
<FromGitter> <tenebrousedge> huh
<FromGitter> <Blacksmoke16> prob is a bug, imma try and fix it
<FromGitter> <tenebrousedge> that's really more than I want to know about ANSI escape codes
<FromGitter> <Blacksmoke16> more than I knew earlier today too ha
<FromGitter> <Blacksmoke16> porting some PHP code and noticed the formatted string's were diff
<FromGitter> <Blacksmoke16> eh, i think ill just file it as a bug :p
<Andriamanitra> in ruby you could do something like "puts str.scan(.{1,#{width}})", i couldn't figure out a way to make it as nice (nasty) in crystal though
<Andriamanitra> i guess "puts str.chars.each_slice(width).map(&.join).join('\n')" is pretty much as good as it gets
<FromGitter> <Blacksmoke16> `str.scan /.{1, #{width}}/`?
<Andriamanitra> yeah forgot the // :p
<FromGitter> <Blacksmoke16> oh for the line wrapping
<FromGitter> <tenebrousedge> `gsub(/.{1, #{width}}/, "# \\0 \n")`
<FromGitter> <tenebrousedge> or something like that
<FromGitter> <Blacksmoke16> i just copied the PHP implementation for now, as it does other things too
<FromGitter> <Blacksmoke16> i/someone else can revisit it later :P
<FromGitter> <Blacksmoke16> ```output.puts "pre <error>Bad thing!</error> post"```
<FromGitter> <Blacksmoke16> can define styles for tags for use in output
duane has joined #crystal-lang
andremedeiros has quit [Read error: Connection reset by peer]
andremedeiros has joined #crystal-lang
_ht has joined #crystal-lang
ua_ has quit [Read error: Connection reset by peer]
ua_ has joined #crystal-lang
<FromGitter> <shootingfly> Hi, everyone. My clients are facing unfortunately an issue with the docker (When I upgrade the crystal version to 1.0.0). execute error: server error Hostname lookup for myscale.api.svc.cluster.local failed: System error
<FromGitter> <shootingfly> Is there anyone who can help me? My customer upgraded a program to crystal 1.0.0 with .local domain. We use docker, crystal 1.0.0-alpine with `crystal build src/main.cr --release --static`.
<FromGitter> <erdnaxeli:cervoi.se> that looks like a network error
<FromGitter> <shootingfly> He rollbacked and retried many times between v0.35.1 and v1.0.0 ⏎ And for sure no issue with previous version v0.35.1 :/
<FromGitter> <shootingfly> I have tested without .local domain in my machine. It is succeed.
hendursaga has quit [Remote host closed the connection]
hendursaga has joined #crystal-lang
hendursa1 has joined #crystal-lang
hendursaga has quit [Ping timeout: 240 seconds]
<FromGitter> <erdnaxeli:cervoi.se> he could try with crystal 1.0 not in an docker
<FromGitter> <erdnaxeli:cervoi.se> to known if it comes from crystal 1.0 or from the alpine version that changed
<FromGitter> <shootingfly> > to known if it comes from crystal 1.0 or from the alpine version that changed ⏎ ⏎ He is a java programmer and knows nothing about Crystal. I released a docker to him and he used it. But I have no .local domain.
<jhass> shootingfly: is not -alpine an option to try? There's historically been some issues around alpine's libc and local/mdns resolution
<jhass> I could imagine it's less about Crystal 1.0 and more a change in alpine version
postmodern has quit [Quit: Leaving]
<straight-shoota> yeah, that's very unlikely to be a Crystal issue
<straight-shoota> to verify, you can try an older alpine base image with Crystal 1.0. It won't be available in APK but you can just grab the generic linux tarball from Github.
mipmip has quit [Read error: Connection reset by peer]
mipmip has joined #crystal-lang
<FromGitter> <shootingfly> It is solved! Because I compiled it in general crystal, not alpine, and then run it in alpine.
<FromGitter> <erdnaxeli:cervoi.se> oh, right
<FromGitter> <shootingfly> Now I compiled it in alpine and ran it in alpine, then worked well.
<FromGitter> <erdnaxeli:cervoi.se> btw, did someone suceeded to make a very small docker image for a crystal executable?
<FromGitter> <erdnaxeli:cervoi.se> I tried to build it in static in alpin then copy it in a "FROM scratch" image, but it doesn't work
<FromGitter> <erdnaxeli:cervoi.se> anyway, alpine is only 5Mo so that's ok
<FromGitter> <Blacksmoke16> just use alpine
<FromGitter> <erdnaxeli:cervoi.se> yep I does exactly that now
<FromGitter> <Blacksmoke16> its still quite small and you get benefits of an OS/package manager and stuff
<FromGitter> <erdnaxeli:cervoi.se> but I saw someone using FROM scratch with golang so I wanted to try
<FromGitter> <Daniel-Worrall> In theory, it should work, but I don't think anybody has taken the time to investigate why some things don't
<straight-shoota> it always depends on what you do...
<straight-shoota> a hello world should certainly run in a scratch image, but when you use more things, there are more expectations about the program's environment
mipmip has quit [Read error: Connection reset by peer]
mipmip has joined #crystal-lang
<FromGitter> <jrei:matrix.org> what does not work erdnaxeli (https://matrix.to/#/@erdnaxeli:cervoi.se)?
mipmip has quit [Read error: Connection reset by peer]
ua_ has quit [Ping timeout: 260 seconds]
ua has joined #crystal-lang
DTZUZU has quit [Read error: Connection reset by peer]
DTZUZU has joined #crystal-lang
<FromGitter> <erdnaxeli:cervoi.se> something with the PATH
<FromGitter> <erdnaxeli:cervoi.se> hmm, `Process.find_executable` find the executable, but then when I try to execute it with `Process.run` I got a "file not found" error: https://gist.github.com/erdnaxeli/df73c9e95010ba874c1ad6ec194b390a
<FromGitter> <erdnaxeli:cervoi.se> j8r (https://matrix.to/#/@jrei:matrix.org): --^
<FromGitter> <tenebrousedge> are you sure the file name is correct?
<FromGitter> <erdnaxeli:cervoi.se> well yes, it was returned by `Process.find_executable`
<FromGitter> <erdnaxeli:cervoi.se> btw self promotion time, this is about this project, which is a tool to skip sponsor segment on youtube videos playing on a chromecast: https://github.com/erdnaxeli/castblock
<FromGitter> <tenebrousedge> can you paste how you're using `find_executable` ?
mipmip has joined #crystal-lang
mipmip has quit [Ping timeout: 240 seconds]
mipmip has joined #crystal-lang
<FromGitter> <erdnaxeli:cervoi.se> https://github.com/erdnaxeli/castblock/blob/main/src/chromecast.cr#L95 and then it is used line 108
<FromGitter> <oprypin:matrix.org> erdnaxeli (https://matrix.to/#/@erdnaxeli:cervoi.se): hmm the only explanation i could see for this is that /usr/bin/go-chromecast is a symlink pointing to a nonexistent destination
mipmip has quit [Ping timeout: 240 seconds]
mipmip has joined #crystal-lang
_ht has quit [Remote host closed the connection]
mipmip has quit [Ping timeout: 252 seconds]
mipmip has joined #crystal-lang
<straight-shoota> According to the dockerfile it is a file
<FromGitter> <erdnaxeli:cervoi.se> using the same dockerfile, changing `FROM scratch` to `FROM alpin` works
<FromGitter> <erdnaxeli:cervoi.se> the file exists, is executable, is not empty: https://gist.github.com/erdnaxeli/f394720b9626d8e3c1e09d31a88c9a1f
<FromGitter> <erdnaxeli:cervoi.se> this is a minimal example
<FromGitter> <erdnaxeli:cervoi.se> so weird
<FromGitter> <Blacksmoke16> try like `File.info?(bin, follow_symlinks: false).try(&.symlink?)`
<FromGitter> <jrei:matrix.org> maybe you haven't properly linked statically...
<FromGitter> <Blacksmoke16> and if that prints `true`, to @oprypin:matrix.org's point, it's prob copying the symlink and the actual file doesnt exist
<FromGitter> <oprypin:matrix.org> @Blacksmoke16: there's code printing part of that file and it start with ELFwhatever
<FromGitter> <jrei:matrix.org> of course Go is not linked statically "magically"
<FromGitter> <Blacksmoke16> ah, fair enough
<FromGitter> <erdnaxeli:cervoi.se> `(File.info?(bin, follow_symlinks: false)).try(&.symlink?) # => false`
<FromGitter> <erdnaxeli:cervoi.se> same error if I copy /bin/ls from alpine
<FromGitter> <jrei:matrix.org> ha nvm that's a crystal error
<FromGitter> <erdnaxeli:cervoi.se> but no error if I copy a binary from the docker contexte
<FromGitter> <erdnaxeli:cervoi.se> and not from a docker stage
<FromGitter> <jrei:matrix.org> it is an error related to the Go binary
<FromGitter> <erdnaxeli:cervoi.se> no
<FromGitter> <oprypin:matrix.org> uhh
<FromGitter> <jrei:matrix.org> 'Error executing process: '/bin/go-chromecast': No such file or directory (File::NotFoundError)'
<FromGitter> <jrei:matrix.org> the go-chromecast file is not a proper one
<FromGitter> <jrei:matrix.org> Go does not link statically magically, you have to pass LDFLAGS and some stuff
<FromGitter> <erdnaxeli:cervoi.se> I got the same error if I do `COPY --from=1 /bin/ls /bin/go-chromecast`
<FromGitter> <erdnaxeli:cervoi.se> ah so the file exist but cannot be executed?
<FromGitter> <erdnaxeli:cervoi.se> the error is confusing then
<FromGitter> <oprypin:matrix.org> > ENOENT The file pathname or a script or ELF interpreter does not exist
<FromGitter> <oprypin:matrix.org> maybe some of these files require this ELF interpreter and some don't
<FromGitter> <jrei:matrix.org> yes, that's what happens.
<FromGitter> <oprypin:matrix.org> is `ld.so` and ELF interpreter or what
<FromGitter> <Blacksmoke16> isnt ELF for like debug symbols or something?
<straight-shoota> that's DWARF
<straight-shoota> ELF is the executable format
<FromGitter> <Blacksmoke16> ah, i was close. Same height diff region :P
<FromGitter> <jrei:matrix.org> erdnaxeli (https://matrix.to/#/@erdnaxeli:cervoi.se): any, no issue with Crystal: the code is executing as expected
<FromGitter> <erdnaxeli:cervoi.se> ok you're right, go needs some parameters to build a static binary
<FromGitter> <erdnaxeli:cervoi.se> yep
<FromGitter> <erdnaxeli:cervoi.se> the error got me
<FromGitter> <erdnaxeli:cervoi.se> anyway alpine is fine ^^
<FromGitter> <oprypin:matrix.org> weird, because some executable i made, if it's missing dynamic libraries, it doesn't cause ENOENT
<FromGitter> <jrei:matrix.org> last time I tried to compile Go statically I needed `export LDFLAGS='-extldflags "-static -fuse-ld=bfd"'`
<straight-shoota> @oprypin I suppose the issue is not the missing library but the missing loader
<FromGitter> <erdnaxeli:cervoi.se> that's what seem to be needed indeed
<FromGitter> <oprypin:matrix.org> yes
<FromGitter> <jrei:matrix.org> strange the bfd linker was needed, maybe it is simpler now
mipmip has quit [Ping timeout: 252 seconds]
mipmip has joined #crystal-lang
<FromGitter> <tenebrousedge> TIL ENOENT can happen for ELF interpreter failures
mipmip has quit [Ping timeout: 252 seconds]
mipmip has joined #crystal-lang
mipmip has quit [Ping timeout: 260 seconds]
mipmip has joined #crystal-lang
mipmip has quit [Ping timeout: 252 seconds]
mipmip has joined #crystal-lang
mipmip has quit [Remote host closed the connection]
mipmip has joined #crystal-lang
mipmip has quit [Ping timeout: 246 seconds]