01mf02 / jaq

A jq clone focussed on correctness, speed, and simplicity
MIT License
2.76k stars 75 forks source link

Bug using | more #183

Closed hellishvictor closed 1 month ago

hellishvictor commented 5 months ago

Hi, here on Win 7 x64 using | more on: curl -s https://theunitedstates.io/congress-legislators/legislators-current.json | jaq.exe --color=never .[] | more

it shows:

?┼?=>?┼┼????=>?????
┼????????:?┼┼????????┼???????????┼???????>???????┼??????>????┼???>?┼┼┼??????
┼┼??????
┼??┼┼????????┼?????=>?????????┼????????>???┼┼????????????????┼┼?????>???┼????>????┼????????????┼┼???
?????=>???????
??┼??=>?┼┼????????=?┼┼???>?????┼????????>????????┼?????>?┼┼?????>???????┼┼????>??┼?
????>?┼┼?┼┼┼??=>????┼┼????>???????┼┼┼???????????┼┼???=>?~?┼┼┼?????>??┼┼┼??????????┼┼?
┼?
┼┼????????┼┼┼????????????┼┼??=>???????┼┼┼???????
┼┼?????????┼┼????>??????┼??┼┼?┼┼┼??=>????┼┼????>???????┼┼┼???????????┼┼???=>?~?┼┼┼?????>??┼┼┼???????
???┼┼??┼??┼┼????????┼┼┼???????????
┼┼??=>???????┼┼┼????????┼┼?????????┼┼????>??????┼??┼┼?┼┼┼??=>???
┼┼????>???????┼┼┼???????????┼┼???=>?~?┼┼┼?????>??┼┼┼??????????┼┼?
┼?
┼┼????????┼┼┼????????????┼┼??=>???????┼┼┼???????
┼┼?????????┼┼????>??????┼┼┼??????????????????????┼??┼┼?┼┼┼??=>????┼┼????>???????┼┼┼???????????┼┼???=
>?~?┼┼┼?????>??┼┼┼??????????
┼┼???>??????????????????┼┼??┼??┼┼????????┼┼┼????????????┼┼??=>???????┼┼┼????????┼┼????>?
┼┼????>??????┼┼┼??????????????????┼┼?????>????????????????????????????┼┼???=>????????┼┼┼???????????
┼┼????????????????????????????
┼┼???????????????????????┼??┼┼?┼┼┼??=>???
┼┼????>???????┼┼┼???????????┼┼???=>?~?┼┼┼??????????
┼┼????>??┼┼???>????????????????┼┼┼?????????????????????????????????┼┼┼????????????
┼┼???>????????┼┼┼???????>????????????????????┼┼┼???=>????4?????????????┼┼????????????
-- Más  --

Cheers.

01mf02 commented 5 months ago

This is very strange. On Linux, I cannot reproduce this problem. What does curl -s https://theunitedstates.io/congress-legislators/legislators-current.json | more give you?

hellishvictor commented 5 months ago
[
  {
    "id": {
      "bioguide": "B000944",
      "thomas": "00136",
      "lis": "S307",
      "govtrack": 400050,
      "opensecrets": "N00003535",
      "votesmart": 27018,
      "fec": [
        "H2OH13033",
        "S6OH00163"
      ],
      "cspan": 5051,
      "wikipedia": "Sherrod Brown",
      "house_history": 9996,
      "ballotpedia": "Sherrod Brown",
      "maplight": 168,
      "icpsr": 29389,
      "wikidata": "Q381880",
      "google_entity_id": "kg:/m/034s80"
    },
    "name": {
      "first": "Sherrod",
-- Más  --
01mf02 commented 5 months ago

Ok. Can you tell me the output of the following commands?

curl -s https://theunitedstates.io/congress-legislators/legislators-current.json > legislators-current.json
jaq.exe --color=never .[] legislators-current.json | more

And:

type legislators-current.json | jaq.exe --color=never .[] | more

And:

type legislators-current.json | jaq.exe --color=never .[]
hellishvictor commented 5 months ago

The first two output the same wrong data that is on the first comment; I just switched to jaq for get more speed, but not problem at all when using jq, dasel, or any other. For examples:

curl -s http://programminghistorian.org/assets/jq_rkm.json | jq.exe .[] | more

48
359
[
  {
    "links": {
      "self": "https://www.rijksmuseum.nl/api/nl/collection/SK-C-5",
      "web": "https://www.rijksmuseum.nl/nl/collectie/SK-C-5"
    },
    "id": "nl-SK-C-5",
    "objectNumber": "SK-C-5",
    "title": "Schutters van wijk II onder leiding van kapitein Frans Banninck Cocq, bekend als de ÔÇ
ÿNachtwachtÔÇÖ",
    "hasImage": true,
    "principalOrFirstMaker": "Rembrandt Harmensz. van Rijn",
    "longTitle": "Schutters van wijk II onder leiding van kapitein Frans Banninck Cocq, bekend als d
e ÔÇÿNachtwachtÔÇÖ, Rembrandt Harmensz. van Rijn, 1642",
    "showImage": true,
    "permitDownload": true,
    "webImage": {
      "guid": "3ae88fe0-021c-41ae-a4ce-cc70b7bc6295",
      "offsetPercentageX": 50,
      "offsetPercentageY": 100,
      "width": 2500,
      "height": 2034,
-- Más  --

curl -s http://programminghistorian.org/assets/jq_rkm.json | dasel -r json -w yaml | more

elapsedMilliseconds: 48
count: 359
artObjects:
  - links:
      self: https://www.rijksmuseum.nl/api/nl/collection/SK-C-5
      web: https://www.rijksmuseum.nl/nl/collectie/SK-C-5
    id: nl-SK-C-5
    objectNumber: SK-C-5
    title: Schutters van wijk II onder leiding van kapitein Frans Banninck Cocq, bekend als de ÔÇÿNa
chtwachtÔÇÖ
    hasImage: true
    principalOrFirstMaker: Rembrandt Harmensz. van Rijn
    longTitle: Schutters van wijk II onder leiding van kapitein Frans Banninck Cocq, bekend als de Ô
ÇÿNachtwachtÔÇÖ, Rembrandt Harmensz. van Rijn, 1642
    showImage: true
    permitDownload: true
    webImage:
      guid: 3ae88fe0-021c-41ae-a4ce-cc70b7bc6295
      offsetPercentageX: 50
      offsetPercentageY: 100
      width: 2500
      height: 2034
      url: http://lh6.ggpht.com/ZYWwML8mVFonXzbmg2rQBulNuCSr3rAaf5ppNcUc2Id8qXqudDL1NSYxaqjEXyDLSbeN
FzOHRu0H7rbIws0Js4d7s_M=s0
-- Más  --
hellishvictor commented 5 months ago

#177 solved this.

01mf02 commented 5 months ago

Great!

hellishvictor commented 2 months ago

Hi, it seems that it's not solved, the bug is still on the latest v2.0.0-alpha and also on v1.6.0 (I've downloaded and builded it just for confirm it). Anything I can help let me know.

01mf02 commented 2 months ago

@hellishvictor, can you post the output of the following commands, using v2.0.0-alpha.1?

$ jaq -n '[0]' | more
$ jaq -n --color=never '[0]' | more
$ jaq -n '[0]'
$ jaq -n --color=never '[0]'
hellishvictor commented 2 months ago

@hellishvictor, can you post the output of the following commands, using v2.0.0-alpha.1?

Here is:

$ jaq -n '[0]' | more
$ jaq -n --color=never '[0]' | more
`?┼??`

$ jaq -n '[0]' $ jaq -n --color=never '[0]'


[
0
]
01mf02 commented 2 months ago

Ok, this is definitely weird.

I've prepared a sample program for you:

use std::io::{self, Write};

fn with_stdout<T>(f: impl FnOnce(&mut io::StdoutLock) -> io::Result<T>) -> io::Result<T> {
    let mut stdout = io::stdout().lock();
    let y = f(&mut stdout)?;
    stdout.flush()?;
    Ok(y)
}

fn main() -> io::Result<()> {
    with_stdout(|out| {
        writeln!(out, "[")?;
        writeln!(out, "  0")?;
        writeln!(out, "]")
    })
}

Can you save the above program as main.rs, compile it with rustc main.rs, then run main.exe | more? Let us pray that it yields ?┼?? ...

hellishvictor commented 2 months ago

It does: ?┼??

01mf02 commented 2 months ago

Great. What does the following program do (again running rustc main.rs, then main.exe | more)?

fn main() {
    println!("[");
    println!("  0");
    println!("]");
}
hellishvictor commented 2 months ago

It outputs the same.

01mf02 commented 2 months ago

OK. Then you'll likely have this behaviour with any Rust program, not just jaq. Therefore, this issue can only be solved at Rust-level. Can you open an issue at https://github.com/rust-lang/rust?

01mf02 commented 1 month ago

Closing this because this issue is not only related to jaq.