about summary refs log tree commit diff stats
path: root/apps/tile
diff options
context:
space:
mode:
Diffstat (limited to 'apps/tile')
-rw-r--r--apps/tile/environment.mu24
-rw-r--r--apps/tile/main.mu4
-rw-r--r--apps/tile/value-stack.mu5
3 files changed, 30 insertions, 3 deletions
diff --git a/apps/tile/environment.mu b/apps/tile/environment.mu
index 94fe8476..d006d245 100644
--- a/apps/tile/environment.mu
+++ b/apps/tile/environment.mu
@@ -1415,13 +1415,31 @@ $render-value:body: {
     break-if-!=
     var val-ah/eax: (addr handle array byte) <- get val, text-data
     var val-string/eax: (addr array byte) <- lookup *val-ah
+    compare val-string, 0
+    break-if-=
+    var orig-len/ecx: int <- length val-string
+    var truncated: (handle array byte)
+    var truncated-ah/esi: (addr handle array byte) <- address truncated
+    substring val-string, 0, 0xc, truncated-ah
+    var truncated-string/eax: (addr array byte) <- lookup *truncated-ah
+#?     {
+#?       var foo/eax: int <- copy truncated-string
+#?       print-int32-hex 0, foo
+#?       print-string 0, "\n"
+#?     }
+    var len/edx: int <- length truncated-string
     start-color screen, 0xf2, 7
-    print-code-point screen, 0x275d
+    print-code-point screen, 0x275d  # open-quote
     reset-formatting screen
     start-color screen, 0, 7
-    print-string screen, val-string
+    print-string screen, truncated-string
     start-color screen, 0xf2, 7
-    print-code-point screen, 0x275e
+    compare len, orig-len
+    {
+      break-if-=
+      print-code-point screen, 0x2026  # ellipses
+    }
+    print-code-point screen, 0x275e  # close-quote
     reset-formatting screen
     break $render-value:body
   }
diff --git a/apps/tile/main.mu b/apps/tile/main.mu
index 08e6532b..b02dc386 100644
--- a/apps/tile/main.mu
+++ b/apps/tile/main.mu
@@ -77,6 +77,10 @@ fn test {
   initialize-environment-with-fake-screen env, 5, 0xa
   var g/eax: grapheme <- copy 0x22  # '"'
   process env, g
+  g <- copy 0x61  # 'a'
+  process env, g
+  g <- copy 0x22  # '"'
+  process env, g
   render env
 }
 
diff --git a/apps/tile/value-stack.mu b/apps/tile/value-stack.mu
index a6ba4f0f..99e013bb 100644
--- a/apps/tile/value-stack.mu
+++ b/apps/tile/value-stack.mu
@@ -172,6 +172,11 @@ fn value-width _v: (addr value) -> result/eax: int {
       break-if-=
       var _out/eax: int <- length s
       out <- copy _out
+      compare out, 0xd  # max string size
+      {
+        break-if-<=
+        out <- copy 0xd
+      }
       break $value-width:body
     }
     {
olor: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
require 'code/directory'

class Directory::Entry
	# Let's just cache every shit, because i don't want
	# to call File methods all the time

	BAD_TIME = Time.at(1)
	MIMETYPES = Marshal.load(File.read(
		File.join(MYDIR, 'data', 'mime.dat')))

	
	## wrapper
	def use() Use end
	module Use
		def self.method_missing(app,*_) throw(:use, app) end
		def self.no_handler()           throw(:use, nil) end
	end

	def initialize(dirname, basename=nil)
		if basename
			@path = File.join(dirname, basename)
			@dirname = dirname
			@basename = basename
		else
			@path = dirname
			@dirname = File.dirname(dirname)
			@basename = File.basename(dirname)
		end
		@name, @ext = @basename.split_at_last_dot
		@ext = @ext.downcase
		if @ext == 'part'
			@name, @ext = @name.split_at_last_dot
			@ext = @ext.downcase
		end
		@size = 0
		@exists = false
		@rights = '--unread--'
		@readlink = ''
		@symlink = false
		@writable = false
		@infostring = ''
		@mimetype = nil
		@executable = false
		@type = :nonexistent
		@mtime = BAD_TIME
		@ctime = BAD_TIME
		@marked = false
	end

	attr_reader(*%w{
		basename mtime rights type path ext mimetype
		infostring readlink basename size ctime name
	})

	attr_accessor(:marked)
	
	def to_s() @path end
	def exists?() @exists end
	def marked?() @marked end
	def symlink?() @symlink end
	def socket?() @type == :socket end
	def video?() @video ||= @mimetype && @mimetype =~ /^video\// end
	def audio?() @sound ||= @mimetype && @mimetype =~ /^audio\// end
	def image?() @image ||= @mimetype && @mimetype =~ /^image\// end
	def broken_symlink?() @symlink and !@exists end
	def dir?() @type == :dir end
	def file?() @type == :file end
	def writable?() @writable end
	def executable?() @executable end
	alias movie? video?
	alias sound? audio?

	def displayname()
		@displayname ||= @basename.ascii_only_if(Option.ascii_only)
	end

	def handler()
		## get_handler has to be defined in another file
		@handler ||= catch(:use) do
			get_handler
		end
	end

	def delete!
		if @type == :dir
			Dir.delete(@path) rescue nil
		else
			File.delete(@path) rescue nil
		end
	end

	def refresh
		if File.exists?(@path)
			if File.ctime(@path) != @ctime
				get_data
			end
		else
			get_data
		end
	end

	def sh
		@path.sh
	end

	def in? path
		to_s[0, path.size] == path
	end

	def get_data
		@size = 0
		@infostring = ''

		@exists = File.exists?(@path)
		if @exists
			@writable = File.writable?(@path)
			@symlink = File.symlink?(@path)
			if @symlink
				@readlink = File.readlink(@path)
			end
			if File.directory?(@path)
				@type = :dir
				begin
					sz = Dir.entries(@path).size - 2
					@size = sz
				rescue
					sz = "?"
				end
				@infostring << "#{sz}"
			elsif File.socket?(@path)
				@type = :socket
			else
				@type = :file
				@mimetype = MIMETYPES[@ext]
				@size = File.size(@path)
				if File.size?(@path)
					@infostring << " #{File.size(@path).bytes 2}"
				else
					@infostring << ""
				end
			end
			@rights = File.modestr(@path)
			@executable = File.executable?(@path)
			@mtime = File.mtime(@path)
			@ctime = File.ctime(@path)

		else
			if File.symlink?(@path)
				@readlink = File.readlink(@path) rescue nil
				@infostring = '->'
				@symlink = true
			else
				@symlink = false
			end
			@executable = false
			@writable = false
			@type = :nonexistent
			@rights = '----------'
			@mtime = BAD_TIME
			@ctime = BAD_TIME
		end
	end
end