<commit_before>require "rendertext"
require "keys"
require "graphics"

FileChooser = {
	-- Class vars:
	
	-- font for displaying file/dir names
	face = freetype.newBuiltinFace("sans", 25),
	fhash = "s25",
	-- font for paging display
	sface = freetype.newBuiltinFace("sans", 16),
	sfhash = "s16",
	-- spacing between lines
	spacing = 40,

	-- state buffer
	dirs = nil,
	files = nil,
	items = 0,
	path = "",
	page = 1,
	current = 1,
	oldcurrent = 0,
}

function FileChooser:readdir()
	self.dirs = {}
	self.files = {}
	for f in lfs.dir(self.path) do
		if lfs.attributes(self.path.."/"..f, "mode") == "directory" and f ~= "." and not string.match(f, "^%.[^.]") then
			table.insert(self.dirs, f)
		elseif string.match(f, ".+%.[pP][dD][fF]$") then
			table.insert(self.files, f)
		end
	end
	table.sort(self.dirs)
	table.sort(self.files)
end

function FileChooser:setPath(newPath)
	self.path = newPath
	self:readdir()
	self.items = #self.dirs + #self.files
	if self.items == 0 then
		return nil
	end
	self.page = 1
	self.current = 1
	return true
end

function FileChooser:rotationMode()
	--[[
	return code for four kinds of rotation mode:

  0 for no rotation, 
	1 for landscape with bottom on the right side of screen, etc.

	        2
	    ---------
	   |         |
	   |         |
	   |         |
	 3 |         | 1
	   |         |
	   |         |
	   |         |
	    ---------
	        0
	--]]

	orie_fd = io.open("/sys/module/eink_fb_hal_broads/parameters/bs_orientation", "r")
	updown_fd = io.open("/sys/module/eink_fb_hal_broads/parameters/bs_upside_down", "r")
	mode = orie_fd:read() + (updown_fd:read() * 2)
	return mode
end

function FileChooser:choose(ypos, height)
	local perpage = math.floor(height / self.spacing) - 1
	local pagedirty = true
	local markerdirty = false

	prevItem = function ()
		if self.current == 1 then
			if self.page > 1 then
				self.current = perpage
				self.page = self.page - 1
				pagedirty = true
			end
		else
			self.current = self.current - 1
			markerdirty = true
		end
	end<commit_msg>Make sure rotation mode is correctly read with assert<commit_after>require "rendertext"
require "keys"
require "graphics"

FileChooser = {
	-- Class vars:
	
	-- font for displaying file/dir names
	face = freetype.newBuiltinFace("sans", 25),
	fhash = "s25",
	-- font for paging display
	sface = freetype.newBuiltinFace("sans", 16),
	sfhash = "s16",
	-- spacing between lines
	spacing = 40,

	-- state buffer
	dirs = nil,
	files = nil,
	items = 0,
	path = "",
	page = 1,
	current = 1,
	oldcurrent = 0,
}

function FileChooser:readdir()
	self.dirs = {}
	self.files = {}
	for f in lfs.dir(self.path) do
		if lfs.attributes(self.path.."/"..f, "mode") == "directory" and f ~= "." and not string.match(f, "^%.[^.]") then
			table.insert(self.dirs, f)
		elseif string.match(f, ".+%.[pP][dD][fF]$") then
			table.insert(self.files, f)
		end
	end
	table.sort(self.dirs)
	table.sort(self.files)
end

function FileChooser:setPath(newPath)
	self.path = newPath
	self:readdir()
	self.items = #self.dirs + #self.files
	if self.items == 0 then
		return nil
	end
	self.page = 1
	self.current = 1
	return true
end

function FileChooser:rotationMode()
	--[[
	return code for four kinds of rotation mode:

  0 for no rotation, 
	1 for landscape with bottom on the right side of screen, etc.

	        2
	    ---------
	   |         |
	   |         |
	   |         |
	 3 |         | 1
	   |         |
	   |         |
	   |         |
	    ---------
	        0
	--]]

	orie_fd = assert(io.open("/sys/module/eink_fb_hal_broads/parameters/bs_orientation", "r"))
	updown_fd = assert(io.open("/sys/module/eink_fb_hal_broads/parameters/bs_upside_down", "r"))
	mode = orie_fd:read() + (updown_fd:read() * 2)
	return mode
end

function FileChooser:choose(ypos, height)
	local perpage = math.floor(height / self.spacing) - 1
	local pagedirty = true
	local markerdirty = false

	prevItem = function ()
		if self.current == 1 then
			if self.page > 1 then
				self.current = perpage
				self.page = self.page - 1
				pagedirty = true
			end
		else
			self.current = self.current - 1
			markerdirty = true
		end
	end
{'fraction_non_alphanumeric': 0.1436222005842259, 'fraction_numerical': 0.014118792599805257, 'mean_word_length': 2.607550482879719, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2796778', 'n_tokens_mistral': 1655, 'n_tokens_neox': 1490, 'n_words': 377}