mirror of
				https://github.com/Maks1mS/bubbles.git
				synced 2025-11-03 23:21:22 +03:00 
			
		
		
		
	Arabic pager by default, no RTL for now
This commit is contained in:
		@@ -15,19 +15,19 @@ type PagerType int
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// Pagination rendering options
 | 
					// Pagination rendering options
 | 
				
			||||||
const (
 | 
					const (
 | 
				
			||||||
	Dots PagerType = iota
 | 
						Arabic PagerType = iota
 | 
				
			||||||
	Arabic
 | 
						Dots
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Model is the Tea model for this user interface
 | 
					// Model is the Tea model for this user interface
 | 
				
			||||||
type Model struct {
 | 
					type Model struct {
 | 
				
			||||||
 | 
						Type             PagerType
 | 
				
			||||||
	Page             int
 | 
						Page             int
 | 
				
			||||||
	PerPage          int
 | 
						PerPage          int
 | 
				
			||||||
	TotalPages       int
 | 
						TotalPages       int
 | 
				
			||||||
	ActiveDot        string
 | 
						ActiveDot        string
 | 
				
			||||||
	InactiveDot      string
 | 
						InactiveDot      string
 | 
				
			||||||
	ArabicFormat     string
 | 
						ArabicFormat     string
 | 
				
			||||||
	RTL              bool
 | 
					 | 
				
			||||||
	UseLeftRightKeys bool
 | 
						UseLeftRightKeys bool
 | 
				
			||||||
	UseUpDownKeys    bool
 | 
						UseUpDownKeys    bool
 | 
				
			||||||
	UseHLKeys        bool
 | 
						UseHLKeys        bool
 | 
				
			||||||
@@ -64,13 +64,13 @@ func (m *Model) nextPage() {
 | 
				
			|||||||
// NewModel creates a new model with defaults
 | 
					// NewModel creates a new model with defaults
 | 
				
			||||||
func NewModel() Model {
 | 
					func NewModel() Model {
 | 
				
			||||||
	return Model{
 | 
						return Model{
 | 
				
			||||||
 | 
							Type:             Arabic,
 | 
				
			||||||
		Page:             0,
 | 
							Page:             0,
 | 
				
			||||||
		PerPage:          1,
 | 
							PerPage:          1,
 | 
				
			||||||
		TotalPages:       1,
 | 
							TotalPages:       1,
 | 
				
			||||||
		ActiveDot:        "•",
 | 
							ActiveDot:        "•",
 | 
				
			||||||
		InactiveDot:      "○",
 | 
							InactiveDot:      "○",
 | 
				
			||||||
		ArabicFormat:     "%d/%d",
 | 
							ArabicFormat:     "%d/%d",
 | 
				
			||||||
		RTL:              false,
 | 
					 | 
				
			||||||
		UseLeftRightKeys: true,
 | 
							UseLeftRightKeys: true,
 | 
				
			||||||
		UseUpDownKeys:    false,
 | 
							UseUpDownKeys:    false,
 | 
				
			||||||
		UseHLKeys:        true,
 | 
							UseHLKeys:        true,
 | 
				
			||||||
@@ -125,21 +125,16 @@ func View(model tea.Model) string {
 | 
				
			|||||||
	if !ok {
 | 
						if !ok {
 | 
				
			||||||
		return ""
 | 
							return ""
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						switch m.Type {
 | 
				
			||||||
 | 
						case Dots:
 | 
				
			||||||
		return dotsView(m)
 | 
							return dotsView(m)
 | 
				
			||||||
 | 
						default:
 | 
				
			||||||
 | 
							return arabicView(m)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func dotsView(m Model) string {
 | 
					func dotsView(m Model) string {
 | 
				
			||||||
	var s string
 | 
						var s string
 | 
				
			||||||
	if m.RTL {
 | 
					 | 
				
			||||||
		for i := m.TotalPages; i > 0; i-- {
 | 
					 | 
				
			||||||
			if i == m.Page {
 | 
					 | 
				
			||||||
				s += m.ActiveDot
 | 
					 | 
				
			||||||
				continue
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
			s += m.InactiveDot
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		return s
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	for i := 0; i < m.TotalPages; i++ {
 | 
						for i := 0; i < m.TotalPages; i++ {
 | 
				
			||||||
		if i == m.Page {
 | 
							if i == m.Page {
 | 
				
			||||||
			s += m.ActiveDot
 | 
								s += m.ActiveDot
 | 
				
			||||||
@@ -151,8 +146,5 @@ func dotsView(m Model) string {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func arabicView(m Model) string {
 | 
					func arabicView(m Model) string {
 | 
				
			||||||
	if m.RTL {
 | 
					 | 
				
			||||||
		return fmt.Sprintf(m.ArabicFormat, m.TotalPages, m.Page+1)
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	return fmt.Sprintf(m.ArabicFormat, m.Page+1, m.TotalPages)
 | 
						return fmt.Sprintf(m.ArabicFormat, m.Page+1, m.TotalPages)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user