<commit_before>//
//  TinyConsole.swift
//  TinyConsole
//
//  Created by <NAME> on 28.11.16.
//
//

import UIKit

open class TinyConsole {
    public static var shared = TinyConsole()
    var textView: UITextView?
    
    public static var textAppearance = [
        NSFontAttributeName: UIFont(name: "Menlo", size: 12.0)!,
        NSForegroundColorAttributeName: UIColor.white]
    
    private init() {
    }
    
    var dateFormatter: DateFormatter = {
        let formatter = DateFormatter()
        formatter.dateStyle = DateFormatter.Style.none
        formatter.timeStyle = DateFormatter.Style.medium
        return formatter
    }()
    
    func currentTimeStamp() -> String {
        return dateFormatter.string(from: Date())
    }
    
    public static func scrollToBottom() {
        if let textView = shared.textView, textView.bounds.height < textView.contentSize.height {
            textView.layoutManager.ensureLayout(for: textView.textContainer)
            let offset = CGPoint(x: 0, y: (textView.contentSize.height - textView.frame.size.height))
            textView.setContentOffset(offset, animated: true)
        }
    }
    
    public static func print(_ text: String, global: Bool = true, color: UIColor = UIColor.white) {
        let formattedText = NSMutableAttributedString(string: text)
        let range = NSRange(location: 0, length: formattedText.length)
        
        // set standard text appearance and override foreground color attribute
        formattedText.addAttributes(TinyConsole.textAppearance, range: range)
        formattedText.addAttribute(NSForegroundColorAttributeName, value: color, range: range)
        
        TinyConsole.print(formattedText, global: global)
    }
    
    public static func print(_ text: NSAttributedString, global: Bool = true) {
        if let textView = shared.textView {
            DispatchQueue.main.async {
                let timeStamped = NSMutableAttributedString(string: shared.currentTimeStamp() + " ")
                let range = NSRange(location: 0, length: timeStamped.length)
                
                // set standard text appearance for time-stamp
                timeStamped.addAttributes(TinyConsole.textAppearance, range: range)
                
                timeStamped.append(text)
                timeStamped.append(NSAttributedString(string: "\n"))
                
                let newText = NSMutableAttributedString(attributedString: textView.attributedText)
                newText.append(timeStamped)
                
                textView.attributedText = newText
                TinyConsole.scrollToBottom()
            }
        }
            <commit_msg>Reorder parameter signature of print method<commit_after>//
//  TinyConsole.swift
//  TinyConsole
//
//  Created by <NAME> on 28.11.16.
//
//

import UIKit

open class TinyConsole {
    public static var shared = TinyConsole()
    var textView: UITextView?
    
    public static var textAppearance = [
        NSFontAttributeName: UIFont(name: "Menlo", size: 12.0)!,
        NSForegroundColorAttributeName: UIColor.white]
    
    private init() {
    }
    
    var dateFormatter: DateFormatter = {
        let formatter = DateFormatter()
        formatter.dateStyle = DateFormatter.Style.none
        formatter.timeStyle = DateFormatter.Style.medium
        return formatter
    }()
    
    func currentTimeStamp() -> String {
        return dateFormatter.string(from: Date())
    }
    
    public static func scrollToBottom() {
        if let textView = shared.textView, textView.bounds.height < textView.contentSize.height {
            textView.layoutManager.ensureLayout(for: textView.textContainer)
            let offset = CGPoint(x: 0, y: (textView.contentSize.height - textView.frame.size.height))
            textView.setContentOffset(offset, animated: true)
        }
    }
    
    public static func print(_ text: String, color: UIColor = UIColor.white, global: Bool = true) {
        let formattedText = NSMutableAttributedString(string: text)
        let range = NSRange(location: 0, length: formattedText.length)
        
        // set standard text appearance and override foreground color attribute
        formattedText.addAttributes(TinyConsole.textAppearance, range: range)
        formattedText.addAttribute(NSForegroundColorAttributeName, value: color, range: range)
        
        TinyConsole.print(formattedText, global: global)
    }
    
    public static func print(_ text: NSAttributedString, global: Bool = true) {
        if let textView = shared.textView {
            DispatchQueue.main.async {
                let timeStamped = NSMutableAttributedString(string: shared.currentTimeStamp() + " ")
                let range = NSRange(location: 0, length: timeStamped.length)
                
                // set standard text appearance for time-stamp
                timeStamped.addAttributes(TinyConsole.textAppearance, range: range)
                
                timeStamped.append(text)
                timeStamped.append(NSAttributedString(string: "\n"))
                
                let newText = NSMutableAttributedString(attributedString: textView.attributedText)
                newText.append(timeStamped)
                
                textView.attributedText = newText
                TinyConsole.scrollToBottom()
            }
        }
            
{'fraction_non_alphanumeric': 0.08379681127178347, 'fraction_numerical': 0.004449388209121246, 'mean_word_length': 2.2421875, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '943356', 'n_tokens_mistral': 1491, 'n_tokens_neox': 1410, 'n_words': 325}