Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement 'out', 'outLn', 'err' and 'errLn' functions for outputting 'Text' to corresponding handlers #107

Open
3 tasks
chshersh opened this issue Feb 28, 2023 · 7 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@chshersh
Copy link
Owner

I believe, the title is pretty clear. What's needed specifically:

  • Create Iris.IO module
  • Implement all four functions in this module with documentation and examples
  • Reexport this module from Iris
@chshersh chshersh added enhancement New feature or request good first issue Good for newcomers terminal labels Feb 28, 2023
@chshersh chshersh removed the terminal label Mar 22, 2023
@martinhelmer
Copy link
Collaborator

martinhelmer commented Mar 23, 2023

i'll take care of this.
should i migrate existing internal IO usage as well?
(such as the IO in Question.hs and Formatting.hs)

@chshersh
Copy link
Owner Author

Feel free to take care of this issue!

I think using these functions in others would be a good idea indeed. As long as there're no cyclic dependencies.

@martinhelmer
Copy link
Collaborator

so after this we have slight inconsistencies in naming
raw output

Iris.out
Iris.outLn
Iris.err
Iris.errLn

colored output

Iris.putStdoutColoured
Iris.putStdoutColouredLn
Iris.putStderrColoured
Iris.putStderrColouredLn

OK with that?

Ideally i'd prefer renaming the colored ones to

Iris.outColoured
Iris.outColouredLn
Iris.errColoured
Iris.errColouredLn

but that's not backwards compatible

@martinhelmer
Copy link
Collaborator

Would you like some tests using System.IO.Silently (capture) to capture and check stderr + stdout

or

skip the tests for this since the definitions are trivial.

@martinhelmer
Copy link
Collaborator

martinhelmer commented Mar 26, 2023

overkill example:

import System.IO.Silently (capture_, hCapture_, silence, hCapture, hSilence)
import System.IO (stderr, stdout)

import Iris.IO 
import qualified Iris as IO


checkStdErr f = hCapture_ [stderr] (hSilence [stdout] f)
checkStdOut f = hCapture_ [stdout] (hSilence [stderr] f)

ioSpec :: Spec
ioSpec =
    describe "IO" $ do
        describe "out" $ do 
            it "writes to stdout, no LF " $ checkStdOut (IO.out "TEXT") >>= shouldBe "TEXT"
            it "does not write to stderr " $ checkStdErr (IO.out "TEXT") >>= shouldBe ""
        describe "outLn" $ do 
            it "writes to stdout,  LF " $ checkStdOut (IO.outLn "TEXT") >>= shouldBe "TEXT\n"
            it "does not write to stderr " $ checkStdErr (IO.outLn "TEXT") >>= shouldBe ""
        describe "err" $ do 
            it "writes to sterr, no LF " $ checkStdErr (IO.err "TEXT") >>= shouldBe "TEXT"
            it "does not write to stdout " $ checkStdOut (IO.err "TEXT") >>= shouldBe ""
        describe "errLn" $ do 
            it "writes to stderr,  LF " $ checkStdErr (IO.errLn "TEXT") >>= shouldBe "TEXT\n"
            it "does not write to stdout " $ checkStdOut (IO.errLn "TEXT") >>= shouldBe ""
  IO
    out
      writes to stdout, no LF  [✔]
      does not write to stderr  [✔]
    outLn
      writes to stdout,  LF  [✔]
      does not write to stderr  [✔]
    err
      writes to sterr, no LF  [✔]
      does not write to stdout  [✔]
    errLn
      writes to stderr,  LF  [✔]
      does not write to stdout  [✔]

@chshersh
Copy link
Owner Author

@martinhelmer I like these tests with silently, so let's add them to the implementation as well! 👍🏻

so after this we have slight inconsistencies in naming

My plan is to remove put*Coloured functions completely, so I wouldn't bother with changing their names for now 🙂

Initially, I implemented a design with a separate formatting function, so it could be used in a combination with something like pretty-terminal:

Iris.putStderrColouredLn
    (Pretty.style Pretty.Bold . Pretty.color Pretty.Green)
    "my message"

But I'd rather do #110 properly, so functions like putStderrColouredLn could be removed completely, and the above example will look like:

Iris.errLn $ Iris.bold $ Iris.green "my message"

@martinhelmer
Copy link
Collaborator

martinhelmer commented Mar 26, 2023

ok. roger that. what about the tests? like / no like ?
you answered that already. doh'

martinhelmer added a commit to martinhelmer/iris_issue107 that referenced this issue Mar 26, 2023
martinhelmer added a commit to martinhelmer/iris_issue107 that referenced this issue Mar 26, 2023
martinhelmer added a commit to martinhelmer/iris_issue107 that referenced this issue Apr 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
No open projects
Status: No status
Development

No branches or pull requests

2 participants