JoshCheek / seeing_is_believing

Displays the results of every line of code in your file
1.31k stars 54 forks source link

Question: pretty format #139

Closed ychaker closed 6 years ago

ychaker commented 6 years ago

Hello Again,

Is there an option to format the output?

For example, if I have the followig:

Recipe.all # => #<ActiveRecord::Associations::CollectionProxy [#<Recipe id: 1, day_id: 1, name: "Fattoush", description: "Fattoush is one of the most well known Middle East...", created_at: "2018-07-13 19:16:46", updated_at: "2018-07-13 19:16:58", url: "https://www.allrecipes.com/recipe/223439/arabic-fa...">, #<Recipe id: 2, day_id: 1, name: "Baked Falafel", description: "The baked and healthier version of the traditional...", created_at: "2018-07-13 19:16:46", updated_at: "2018-07...

it would be nice if it were formatted this way:

Recipe.all # => #<ActiveRecord::Associations::CollectionProxy [
  #<Recipe id: 1, day_id: 1, name: "Fattoush", description: "Fattoush is one of the most well known Middle East...", created_at: "2018-07-13 19:16:46", updated_at: "2018-07-13 19:16:58", url: "https://www.allrecipes.com/recipe/223439/arabic-fa...">,
  #<Recipe id: 2, day_id: 1, name: "Baked Falafel", description: "The baked and healthier version of the traditional...", created_at: "2018-07-13 19:16:46", updated_at: "2018-07...
]>

even if without the closing ] and > that would be better.

I know there was a discussion on #44 to handle this, and what I gathered is that the --xmpfilter-style should handle this situation but it isn't.

My vim config is:

" ===== Seeing Is Believing =====
" Assumes you have a Ruby with SiB available in the PATH
" If it doesn't work, you may need to `gem install seeing_is_believing`

" Annotate every line
  nmap <leader>b :%!seeing_is_believing --timeout 12 --line-length 500 --number-of-captures 300 --alignment-strategy chunk<CR>;
" Annotate marked lines
  nmap <leader>n :%.!seeing_is_believing --timeout 12 --line-length 100 --number-of-captures 300 --alignment-strategy chunk --xmpfilter-style<CR>;
" Remove annotations
  nmap <leader>c :%.!seeing_is_believing --clean<CR>;
" Mark the current line for annotation
  nmap <leader>m A # => <Esc>
" Mark the highlighted lines for annotation
  vmap <leader>m :norm A # => <Esc>
JoshCheek commented 6 years ago

Xmlfilter style will handle it, but only if you put the hash rocket on the next line. That sort of tells it that you want to see the previous line, and it should take all the room it needs.

Here's an example:

require 'active_record'
require 'logger'

ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ':memory:'
ActiveRecord::Base.logger = Logger.new $stdout
ActiveSupport::LogSubscriber.colorize_logging = false

ActiveRecord::Schema.define do
  self.verbose = false
  create_table :recipes do |t|
    t.string :name
    t.string :description
    t.string :url
  end
end

class Recipe < ActiveRecord::Base
end

Recipe.create! name: "Fattoush", description: "Fattoush is one of the most well known Middle East..."
Recipe.create! name: "Baked Falafel", description: "The baked and healthier version of the traditional..."
Recipe.all
# => [#<Recipe:0x00007fac31986798
#      id: 1,
#      name: "Fattoush",
#      description: "Fattoush is one of the most well known Middle East...",
#      url: nil>,
#     #<Recipe:0x00007fac30a16628
#      id: 2,
#      name: "Baked Falafel",
#      description: "The baked and healthier version of the traditional...",
#      url: nil>]

# >> D, [2018-08-19T19:46:30.566759 #31457] DEBUG -- :    (0.9ms)  SELECT sqlite_version(*)
# >> D, [2018-08-19T19:46:30.567354 #31457] DEBUG -- :    (0.4ms)  CREATE TABLE "recipes" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar, "description" varchar, "url" varchar)
# >> D, [2018-08-19T19:46:30.604524 #31457] DEBUG -- :    (0.2ms)  CREATE TABLE "ar_internal_metadata" ("key" varchar NOT NULL PRIMARY KEY, "value" varchar, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
# >> D, [2018-08-19T19:46:30.615658 #31457] DEBUG -- :   ActiveRecord::InternalMetadata Load (0.2ms)  SELECT  "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = ? LIMIT ?  [["key", "environment"], ["LIMIT", 1]]
# >> D, [2018-08-19T19:46:30.621745 #31457] DEBUG -- :    (0.1ms)  begin transaction
# >> D, [2018-08-19T19:46:30.623125 #31457] DEBUG -- :   SQL (0.1ms)  INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES (?, ?, ?, ?)  [["key", "environment"], ["value", "default_env"], ["created_at", "2018-08-20 00:46:30.622314"], ["updated_at", "2018-08-20 00:46:30.622314"]]
# >> D, [2018-08-19T19:46:30.623464 #31457] DEBUG -- :    (0.1ms)  commit transaction
# >> D, [2018-08-19T19:46:30.631104 #31457] DEBUG -- :    (0.1ms)  begin transaction
# >> D, [2018-08-19T19:46:30.631892 #31457] DEBUG -- :   SQL (0.1ms)  INSERT INTO "recipes" ("name", "description") VALUES (?, ?)  [["name", "Fattoush"], ["description", "Fattoush is one of the most well known Middle East..."]]
# >> D, [2018-08-19T19:46:30.632400 #31457] DEBUG -- :    (0.1ms)  commit transaction
# >> D, [2018-08-19T19:46:30.632935 #31457] DEBUG -- :    (0.1ms)  begin transaction
# >> D, [2018-08-19T19:46:30.634112 #31457] DEBUG -- :   SQL (0.2ms)  INSERT INTO "recipes" ("name", "description") VALUES (?, ?)  [["name", "Baked Falafel"], ["description", "The baked and healthier version of the traditional..."]]
# >> D, [2018-08-19T19:46:30.634628 #31457] DEBUG -- :    (0.1ms)  commit transaction
# >> D, [2018-08-19T19:46:30.635434 #31457] DEBUG -- :   Recipe Load (0.2ms)  SELECT "recipes".* FROM "recipes"

Here's a test that shows how you run it: https://github.com/JoshCheek/seeing_is_believing/blob/c8d7fa04ae218c49d654f312a34fc2627a2b2749/features/xmpfilter-style.feature#L75-L91

With the keybindings I linked in https://github.com/JoshCheek/seeing_is_believing/issues/138, you would press <Leader>n (I just tried it and it worked for me with those keybindings).

ychaker commented 6 years ago

ah... that worked this time, although I thought I had tried that option before posting the question.

Thank you for the quick response 👍 you're awesome!

JoshCheek commented 6 years ago

Awesome, glad to hear it ^_^