pkl icon indicating copy to clipboard operation
pkl copied to clipboard

Weird repl output and interactions

Open ghyatzo opened this issue 1 year ago • 7 comments

hello, I've been using the repl but the experience has been a bit rough around the edges. I am on windows and perhaps that is why, since i know that window support is just coming together. For example, when I use the repl from the PS there seems to be a struggle with new lines and command submissions:

pkl0> lol = IntSeq(1,10)
lol = IntSeq(1,10)





/* to force the new input I had to close the statement
 * using ;
 */



;
pkl1> lol
IntSeq(1, 10)
pkl2> lil = IntSeq(1, 102);
lil = IntSeq(1, 102)pkl3> // new prompt not on a new line

copy pasting a multiline expression is impossible as it adds : characters on every new line?

pkl5> class MyClass {
        local test = IntSeq(30, 45)
: <---- this guy over here officer
JLine terminal: do you wish to see all 7 possibilities (0 lines)?ocal test = IntSeq(30, 45)
frequencies: Listing<Float>
      }

while the pasted content was

class MyClass {
	local test = IntSeq(30, 45)
	frequencies: Listing<Float>
}

There seems to be some jumbled up text in the error messages:

pkl0> IntSeq(1, 10).step(2.0)
IntSeq(1, 10).step(2.0)ΓÇôΓÇô Pkl Error ΓÇôΓÇô <---- Is this intended? if so, it's a bit weird :D
Expected value of type Int, but got type Float.
Value: 2.0

2620 | external function step(newValue: Int(isNonZero)): IntSeq
                                        ^^^
at pkl.base#IntSeq.step (https://github.com/apple/pkl/blob/0.26.3/stdlib/base.pkl#L2620)

1 | IntSeq(1, 10).step(2.0)
    ^^^^^^^^^^^^^^^^^^^^^^^
at  (repl:pkl0)

pkl1>

Is this an issue with PS?

ghyatzo avatar Oct 31 '24 12:10 ghyatzo

Hm, I can't reproduce this on my machine (running Windows 11 on Parallels).

The weird characters suggests that your terminal is interpreting Pkl output as some other charset. This post on stackoverflow might help you: https://stackoverflow.com/questions/57131654/using-utf-8-encoding-chcp-65001-in-command-prompt-windows-powershell-window

This might solve your issue with terminating prompts too?

bioball avatar Nov 01 '24 03:11 bioball

PS is using the us-ascii encoding:

PS C:\Users\########> $OutputEncoding


IsSingleByte      : True
BodyName          : us-ascii
EncodingName      : US-ASCII
HeaderName        : us-ascii
WebName           : us-ascii
WindowsCodePage   : 1252
IsBrowserDisplay  : False
IsBrowserSave     : False
IsMailNewsDisplay : True
IsMailNewsSave    : True
EncoderFallback   : System.Text.EncoderReplacementFallback
DecoderFallback   : System.Text.DecoderReplacementFallback
IsReadOnly        : True
CodePage          : 20127

out of curiosity, what is the encoding on your parallels VM?

Forcing it to UTF-8 doesn't seem to work?

PS C:\Users\#########> $OutputEncoding = [System.Text.UTF8Encoding]::new()
PS C:\Users\#########> $OutputEncoding


BodyName          : utf-8
EncodingName      : Unicode (UTF-8)
HeaderName        : utf-8
WebName           : utf-8
WindowsCodePage   : 1200
IsBrowserDisplay  : True
IsBrowserSave     : True
IsMailNewsDisplay : True
IsMailNewsSave    : True
IsSingleByte      : False
EncoderFallback   : System.Text.EncoderReplacementFallback
DecoderFallback   : System.Text.DecoderReplacementFallback
IsReadOnly        : True
CodePage          : 65001



PS C:\Users\#########> .\pkl.exe repl
Nov 01, 2024 3:21:28 PM org.jline.utils.Log logr
WARNING: Unable to create a system terminal, creating a dumb terminal (enable debug logging for more information)
Welcome to Pkl 0.26.3.
Type an expression to have it evaluated.
Type :help or :examples for more information.

pkl0> :clear

;
pkl0>

What i noticed just now though, is this line WARNING: Unable to create a system terminal, creating a dumb terminal (enable debug logging for more information) (it was there also before changing encoding) may this be it?

EDIT: I've found out that I was using the built-in Windows PowerShell which apparently it is stuck at 5.1 and left there to die. I've tried installing and using PowerShell7, which uses UTF-8 encoding OOB, but also there I have the same issue:

PowerShell 7.4.6
PS C:\Users\##########> $OutputEncoding

Preamble          :
BodyName          : utf-8
EncodingName      : Unicode (UTF-8)
HeaderName        : utf-8
WebName           : utf-8
WindowsCodePage   : 1200
IsBrowserDisplay  : True
IsBrowserSave     : True
IsMailNewsDisplay : True
IsMailNewsSave    : True
IsSingleByte      : False
EncoderFallback   : System.Text.EncoderReplacementFallback
DecoderFallback   : System.Text.DecoderReplacementFallback
IsReadOnly        : True
CodePage          : 65001

PS C:\Users\##########> .\pkl.exe repl
Nov 01, 2024 3:42:44 PM org.jline.utils.Log logr
WARNING: Unable to create a system terminal, creating a dumb terminal (enable debug logging for more information)
Welcome to Pkl 0.26.3.
Type an expression to have it evaluated.
Type :help or :examples for more information.

pkl0> :clear      <---- Hit ctrl+c to exit here, but the issue persists.
PS C:\Users\##########>

Btw, how do I enable debug logging?

ghyatzo avatar Nov 01 '24 14:11 ghyatzo

Here's what I see:

PS C:\Users\danielchao> $OutputEncoding

IsSingleByte      : True
BodyName          : us-ascii
EncodingName      : US-ASCII
HeaderName        : us-ascii
WebName           : us-ascii
WindowsCodePage   : 1252
IsBrowserDisplay  : False
IsBrowserSave     : False
IsMailNewsDisplay : True
IsMailNewsSave    : True
EncoderFallback   : System.Text.EncoderReplacementFallback
DecoderFallback   : System.Text.DecoderReplacementFallback
IsReadOnly        : True
CodePage          : 20127

Try running the steps in the answer here: https://stackoverflow.com/a/57134096/2460186. Mainly, flow where you check a checkbox in the settings panel, and then restart Windows.

bioball avatar Nov 01 '24 16:11 bioball

I've had console encoding issues with many Java programs on Windows. The only solution that has universally worked for me was to enable "beta support for UTF-8" in Windows as shown here: https://github.com/oracle/graal/issues/8593#issuecomment-2009163353

odenix avatar Nov 01 '24 17:11 odenix

Sorry, this was an issue on my work computer and had to wait the weekend to get back to it. Turning systemwide UTF-8, fixed the mangled characters, and some end line issues. But didn't make everything smooth:

pkl5> 1 + 4
5
pkl6> IntSeq(1, 10).step(2)
IntSeq(1, 10).step(2)IntSeq(1, 10).step(2)                <--- double output?
pkl7> IntSeq(1, 10).step(2.0)
IntSeq(1, 10).step(2.0)–– Pkl Error ––                       <--- No new line? 
Expected value of type Int, but got type Float.
Value: 2.0

2620 | external function step(newValue: Int(isNonZero)): IntSeq
                                        ^^^
at pkl.base#IntSeq.step (https://github.com/apple/pkl/blob/0.26.3/stdlib/base.pkl#L2620)

1 | IntSeq(1, 10).step(2.0)
    ^^^^^^^^^^^^^^^^^^^^^^^
at  (repl:pkl7)

pkl8> :clear               <--- clear still needs a ; and does nothing.

;
pkl8>

also tab completion doesn't work.

ghyatzo avatar Nov 04 '24 09:11 ghyatzo

I did some digging around. It seems that the issue is with jline and missing either the Jansi or JNA libraries (on windows), quoting from the jline readme:

The dependencies are minimal: you may use JLine without any dependency on *nix systems, but in order to support windows or more advanced usage, you will need to add either Jansi or JNA library.

I am very not handy with JAVA, is there a way to include manually those dependencies? Does it need a Java SDK installed?

ghyatzo avatar Nov 04 '24 15:11 ghyatzo

I am very not handy with JAVA, is there a way to include manually those dependencies? Does it need a Java SDK installed?

Unless you're using jpkl, there is no way to fix this yourself. Probably best to wait until this bug has been fixed.

odenix avatar Nov 04 '24 18:11 odenix