<commit_before>{-|
Module      : Client.Image.Utils
Description : Chat message view
Copyright   : (c) <NAME>, 2016
License     : ISC
Maintainer  : <EMAIL>

Provides utilities for formatting Vty Images.
-}

module Client.Image.Utils where

import           Graphics.Vty.Image

-- | Given an image, break the image up into chunks of at most the
-- given width and stack the resulting chunks vertically top-to-bottom.
lineWrap ::
  Int       {- ^ maximum image width -} ->
  Maybe Int {- ^ Indentation of wrapped lines -} ->
  Image     {- ^ unwrapped image     -} ->
  Image     {- ^ wrapped image       -}
lineWrap w mi img
  |imageWidth img > w = cropRight w img <->
                        maybe (lineWrapNoIndent w) (lineWrapIndent w) mi
                              (cropLeft (imageWidth img - w) img)
  | otherwise = img <|> char defAttr ' '


lineWrapNoIndent :: Int -> Image -> Image
lineWrapNoIndent w img
  | imageWidth img > w = cropRight w img <->
                         lineWrapNoIndent w (cropLeft (imageWidth img - w) img)
  | otherwise = img <|> char defAttr ' '
        -- trailing space with default attributes deals with bug in VTY
        -- where the formatting will continue past the end of chat messages

lineWrapIndent :: Int -> Int -> Image -> Image
lineWrapIndent w i img
      | i >= w-10              = lineWrapNoIndent w img --
      | imageWidth img > w - i = pad i 0 0 0 (cropRight (w-i) img) <->
                                lineWrapIndent w i (cropLeft (imageWidth img - w + i) img)
      | otherwise = pad i 0 0 0 img <|> char defAttr ' '<commit_msg>Ensure that indentation stops when it doesn't make sense.<commit_after>{-|
Module      : Client.Image.Utils
Description : Chat message view
Copyright   : (c) <NAME>, 2016
License     : ISC
Maintainer  : <EMAIL>

Provides utilities for formatting Vty Images.
-}

module Client.Image.Utils where

import           Graphics.Vty.Image

-- | Given an image, break the image up into chunks of at most the
-- given width and stack the resulting chunks vertically top-to-bottom.
lineWrap ::
  Int       {- ^ maximum image width -} ->
  Maybe Int {- ^ Indentation of wrapped lines -} ->
  Image     {- ^ unwrapped image     -} ->
  Image     {- ^ wrapped image       -}
lineWrap w mi img
  |imageWidth img > w = cropRight w img <->
                        maybe (lineWrapNoIndent w) (lineWrapIndent w) mi
                              (cropLeft (imageWidth img - w) img)
  | otherwise = img <|> char defAttr ' '


lineWrapNoIndent :: Int -> Image -> Image
lineWrapNoIndent w img
  | imageWidth img > w = cropRight w img <->
                         lineWrapNoIndent w (cropLeft (imageWidth img - w) img)
  | otherwise = img <|> char defAttr ' '
        -- trailing space with default attributes deals with bug in VTY
        -- where the formatting will continue past the end of chat messages

lineWrapIndent :: Int -> Int -> Image -> Image
lineWrapIndent w i img
      | i >= w || w - i < 20   = lineWrapNoIndent w img -- ensure we stop wrapping when it doesn't make sense
      | imageWidth img > w - i = pad i 0 0 0 (cropRight (w-i) img) <->
                                lineWrapIndent w i (cropLeft (imageWidth img - w + i) img)
      | otherwise = pad i 0 0 0 img <|> char defAttr ' '
{'fraction_non_alphanumeric': 0.09599510852950169, 'fraction_numerical': 0.007337205747477835, 'mean_word_length': 2.0984848484848486, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '208529', 'n_tokens_mistral': 989, 'n_tokens_neox': 929, 'n_words': 378}