# Avoiding very long output

**URL:** https://discourse.julialang.org/t/avoiding-very-long-output/23658
**Category:** General Usage
**Tags:** question
**Created:** [April 29, 2019, 3:57pm UTC](https://discourse.julialang.org/t/avoiding-very-long-output/23658 "2019-04-29T15:57:35Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [April 29, 2019, 3:57pm UTC](https://discourse.julialang.org/t/avoiding-very-long-output/23658/1 "2019-04-29T15:57:35Z")

</div>

Occasionally, for custom types, I forget to define a `show` method that respects `limit`. This can happen accidentally even with the best intentions, eg with unfortunate combinations of nested types.

This can lead to very long output in the REPL, which not all terminals and interfaces are happy with.

I am wondering it it would be possible to somehow customize the REPL or the display infrastructure to catch this. Eg when working the REPL, somehow impose a sanity check of cutting off at eg line 100, or after 10000 characters, whichever comes first.

But I don’t know where to start, is it possible to hook into the existing mechanisms for this?

---

<div class="post-metadata">

### Author: ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)
#### Post date: [April 29, 2019, 6:59pm UTC](https://discourse.julialang.org/t/avoiding-very-long-output/23658/2 "2019-04-29T18:59:55Z")

</div>

One way would be to first print into an `IOBuffer` within your `show` method and then to count the number of lines from the `IOBuffer` before truncating and printing it to the display output. If you don’t want to manually code this into each `show` method, then it would have to be coded into the `stdout`?

---

<div class="post-metadata">

### Author: ![tkf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkf/32/17635_2.png) [@tkf](https://discourse.julialang.org/u/tkf)
#### Post date: [April 29, 2019, 7:29pm UTC](https://discourse.julialang.org/t/avoiding-very-long-output/23658/3 "2019-04-29T19:29:43Z")

</div>

I think you can register a custom `AbstractDisplay` to do this. See: [https://docs.julialang.org/en/latest/base/io-network/#Multimedia-I/O-1](https://docs.julialang.org/en/latest/base/io-network/#Multimedia-I/O-1)

If you want an example, I think ElectronDisplay.jl is a good one: [https://github.com/queryverse/ElectronDisplay.jl/blob/master/src/ElectronDisplay.jl](https://github.com/queryverse/ElectronDisplay.jl/blob/master/src/ElectronDisplay.jl)
